naev 0.11.5
nlua_var.c File Reference

Lua Variable module. More...

#include "nlua_var.h"
#include "array.h"
#include "log.h"
#include "nluadef.h"
#include "nstring.h"
#include "nxml.h"
#include "nlua_time.h"
#include "lvar.h"

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 51 of file nlua_var.c.

◆ var_add()

static 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 105 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 137 of file nlua_var.c.

◆ var_cleanup()

void var_cleanup ( void )

Cleans up all the mission variables.

Definition at line 199 of file nlua_var.c.

◆ var_get()

static lvar * var_get ( const char * str)
static

Gets a mission var by name.

Definition at line 60 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 85 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 71 of file nlua_var.c.

◆ varL_peek()

static 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 150 of file nlua_var.c.

◆ varL_pop()

static 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 167 of file nlua_var.c.

◆ varL_push()

static 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 188 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:167
static int varL_push(lua_State *L)
Creates a new mission variable.
Definition nlua_var.c:188
static int varL_peek(lua_State *L)
Gets the mission variable value of a certain name.
Definition nlua_var.c:150

Mission variable Lua methods.

Definition at line 39 of file nlua_var.c.

◆ var_stack

lvar* var_stack = NULL
static

Stack of mission variables.

Definition at line 32 of file nlua_var.c.