naev 0.12.5
nlua_var.c File Reference

Lua Variable module. More...

#include "nlua_var.h"
#include "array.h"
#include "lvar.h"
#include "nxml.h"
Include dependency graph for nlua_var.c:

Go to the source code of this file.

Functions

static int varL_peek (lua_State *L)
 Gets the mission variable value of a certain name.
static int varL_pop (lua_State *L)
 Pops a mission variable off the stack, destroying it.
static int varL_push (lua_State *L)
 Creates a new mission variable.
int nlua_loadVar (nlua_env env)
 Loads the mission variable Lua library.
static lvarvar_get (const char *str)
 Gets a mission var by name.
int var_save (xmlTextWriterPtr writer)
 Saves the mission variables.
int var_load (xmlNodePtr parent)
 Loads the vars from XML file.
static int var_add (lvar *new_var, int sort)
 Adds a var to the stack, strings will be SHARED, don't free.
int var_checkflag (const char *str)
 Mission variable Lua bindings.
void var_cleanup (void)
 Cleans up all the mission variables.

Variables

static lvarvar_stack = NULL
static const luaL_Reg var_methods []

Detailed Description

Lua Variable module.

Definition in file nlua_var.c.

Function Documentation

◆ nlua_loadVar()

int nlua_loadVar ( nlua_env env)

Loads the mission variable Lua library.

Parameters
envLua environment.
Returns
0 on success.

Definition at line 45 of file nlua_var.c.

◆ var_add()

int var_add ( lvar * new_var,
int sort )
static

Adds a var to the stack, strings will be SHARED, don't free.

Parameters
new_varVariable to add.
sortWhether or not to sort.
Returns
0 on success.

Definition at line 99 of file nlua_var.c.

◆ var_checkflag()

int var_checkflag ( const char * str)

Mission variable Lua bindings.

Mission variables are similar to Lua variables, but are conserved for each player across all the missions. They are good for storing campaign or other global values.

Typical usage would be:

v = var.peek( "es_misn" ) -- Get the value
if v == nil then -- Doesn't exist, so create
var.push( "es_misn", 1 )
else
var.push( "es_misn", v+1 ) -- Increment value
end

Lua module: var

Checks to see if a mission var exists.

Parameters
strName of the mission var.
Returns
1 if it exists, 0 if it doesn't.

Definition at line 131 of file nlua_var.c.

◆ var_cleanup()

void var_cleanup ( void )

Cleans up all the mission variables.

Definition at line 194 of file nlua_var.c.

◆ var_get()

lvar * var_get ( const char * str)
static

Gets a mission var by name.

Definition at line 54 of file nlua_var.c.

◆ var_load()

int var_load ( xmlNodePtr parent)

Loads the vars from XML file.

Parameters
parentParent node containing the variables.
Returns
0 on success.

Definition at line 79 of file nlua_var.c.

◆ var_save()

int var_save ( xmlTextWriterPtr writer)

Saves the mission variables.

Parameters
writerXML Writer to use.
Returns
0 on success.

Definition at line 65 of file nlua_var.c.

◆ varL_peek()

int varL_peek ( lua_State * L)
static

Gets the mission variable value of a certain name.

Lua function parameter: string name Name of the mission variable to get. Lua return parameter: The value of the mission variable which will depend on what type it is.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: peek

Definition at line 144 of file nlua_var.c.

◆ varL_pop()

int varL_pop ( lua_State * L)
static

Pops a mission variable off the stack, destroying it.

This does not give you any value and destroys it permanently (or until recreated).

Lua function parameter: string name Name of the mission variable to pop.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: pop

Definition at line 162 of file nlua_var.c.

◆ varL_push()

int varL_push ( lua_State * L)
static

Creates a new mission variable.

This will overwrite existing vars, so it's a good way to update the values of different mission variables.

Lua function parameter: string name Name to use for the new mission variable. Lua function parameter: value Value of the new mission variable. Accepted types are: nil, bool, string or number.

Parameters
LLua State
Returns
Number of variables on the Lua State stack.

Lua function: push

Definition at line 183 of file nlua_var.c.

Variable Documentation

◆ var_methods

const luaL_Reg var_methods[]
static
Initial value:
= {
{ "peek", varL_peek },
{ "pop", varL_pop },
{ "push", varL_push },
{ 0, 0 } }
static int varL_pop(lua_State *L)
Pops a mission variable off the stack, destroying it.
Definition nlua_var.c:162
static int varL_push(lua_State *L)
Creates a new mission variable.
Definition nlua_var.c:183
static int varL_peek(lua_State *L)
Gets the mission variable value of a certain name.
Definition nlua_var.c:144

Mission variable Lua methods.

Definition at line 34 of file nlua_var.c.

◆ var_stack

lvar* var_stack = NULL
static

Stack of mission variables.

Definition at line 26 of file nlua_var.c.