20static int lvar_cmp(
const void *p1,
const void *p2 );
26static int lvar_cmp(
const void *p1,
const void *p2 )
28 const lvar *mv1, *mv2;
29 mv1 = (
const lvar *)p1;
30 mv2 = (
const lvar *)p2;
31 return strcmp( mv1->
name, mv2->
name );
43 const lvar mv = { .name = (
char *)str };
63 lua_pushnumber( L, v->d.num );
66 lua_pushboolean( L, v->d.b );
69 lua_pushstring( L, v->d.str );
91 if (lua_isnil( L, idx ))
96 }
else if (lua_type( L, idx ) == LUA_TNUMBER) {
98 var.
d.
num = (double)lua_tonumber( L, idx );
99 }
else if (lua_isboolean( L, idx )) {
100 var.
type = LVAR_BOOL;
101 var.
d.
b = lua_toboolean( L, idx );
102 }
else if (lua_type( L, idx ) == LUA_TSTRING) {
104 var.
d.
str = strdup( lua_tostring( L, idx ) );
108 DEBUG(
"Invalid parameter for %s.", __func__ );
109 luaL_error( L,
"Invalid parameter for %s.", __func__ );
114 var.
name = strdup( name );
203 const lvar *v = &arr[i];
204 xmlw_startElem( writer,
"var" );
206 xmlw_attr( writer,
"name",
"%s", v->name );
210 xmlw_attr( writer,
"type",
"nil" );
213 xmlw_attr( writer,
"type",
"num" );
214 xmlw_str( writer,
"%f", v->d.num );
217 xmlw_attr( writer,
"type",
"bool" );
218 xmlw_str( writer,
"%d", v->d.b );
221 xmlw_attr( writer,
"type",
"str" );
222 xmlw_str( writer,
"%s", v->d.str );
225 xmlw_attr( writer,
"type",
"time" );
226 xmlw_str( writer,
"%" TIME_PRI, v->d.time );
229 xmlw_endElem( writer );
244 xmlNodePtr node = parent->xmlChildrenNode;
246 xml_onlyNodes( node );
247 if (!xml_isNode( node,
"var" )) {
248 WARN( _(
"Lua Var stack has unknown node '%s'!" ), xml_get( node ) );
253 xmlr_attr_strd( node,
"name", var.
name );
254 xmlr_attr_strd( node,
"type", str );
255 if (strcmp( str,
"nil" ) == 0)
257 else if (strcmp( str,
"num" ) == 0) {
259 var.
d.
num = xml_getFloat( node );
260 }
else if (strcmp( str,
"bool" ) == 0) {
261 var.
type = LVAR_BOOL;
262 var.
d.
b = xml_getInt( node );
263 }
else if (strcmp( str,
"str" ) == 0) {
265 var.
d.
str = xml_getStrd( node );
266 }
else if (strcmp( str,
"time" ) == 0) {
267 var.
type = LVAR_TIME;
268 var.
d.
time = xml_getLong( node );
270 WARN( _(
"Unknown var type '%s'" ), str );
277 }
while (xml_nextNode( node ));
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
int lvar_addArray(lvar **arr, const lvar *new_var, int sort)
Adds a var to a var array.
void lvar_rmArray(lvar **arr, lvar *rm_var)
Removes a var from a var array.
static int lvar_cmp(const void *p1, const void *p2)
Compares two lua variable names. For use with qsort/bsearch.
lvar * lvar_get(const lvar *arr, const char *str)
Gets a lua var by name.
void lvar_freeArray(lvar *arr)
Frees a variable array.
lvar lvar_tovar(lua_State *L, const char *name, int idx)
Gets a lua variable from an index from a lua state.
int lvar_save(const lvar *arr, xmlTextWriterPtr writer)
Saves the mission variables.
lvar * lvar_load(xmlNodePtr parent)
Loads the vars from XML file.
int lvar_push(lua_State *L, const lvar *v)
Pushes a lua var to a lua state.
static void lvar_free(lvar *var)
Frees a lua variable.
ntime_t * lua_pushtime(lua_State *L, ntime_t time)
Pushes a time on the stack.
int lua_istime(lua_State *L, int ind)
Checks to see if ind is a time.
ntime_t luaL_validtime(lua_State *L, int ind)
Gets a time directly.
Contains a mission variable.
union lvar::@111057267254147367313074135027107120046157027350 d