Merge branch 'findvar' into 'next'
CV_FindVar for Lua See merge request STJr/SRB2!583
This commit is contained in:
commit
12e87d58b4
|
@ -54,7 +54,7 @@ static void COM_Add_f(void);
|
||||||
static void CV_EnforceExecVersion(void);
|
static void CV_EnforceExecVersion(void);
|
||||||
static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr);
|
static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr);
|
||||||
static boolean CV_Command(void);
|
static boolean CV_Command(void);
|
||||||
static consvar_t *CV_FindVar(const char *name);
|
consvar_t *CV_FindVar(const char *name);
|
||||||
static const char *CV_StringValue(const char *var_name);
|
static const char *CV_StringValue(const char *var_name);
|
||||||
static consvar_t *consvar_vars; // list of registered console variables
|
static consvar_t *consvar_vars; // list of registered console variables
|
||||||
|
|
||||||
|
@ -1106,7 +1106,7 @@ static const char *cv_null_string = "";
|
||||||
* \return Pointer to the variable if found, or NULL.
|
* \return Pointer to the variable if found, or NULL.
|
||||||
* \sa CV_FindNetVar
|
* \sa CV_FindNetVar
|
||||||
*/
|
*/
|
||||||
static consvar_t *CV_FindVar(const char *name)
|
consvar_t *CV_FindVar(const char *name)
|
||||||
{
|
{
|
||||||
consvar_t *cvar;
|
consvar_t *cvar;
|
||||||
|
|
||||||
|
|
|
@ -149,6 +149,9 @@ void CV_ToggleExecVersion(boolean enable);
|
||||||
// register a variable for use at the console
|
// register a variable for use at the console
|
||||||
void CV_RegisterVar(consvar_t *variable);
|
void CV_RegisterVar(consvar_t *variable);
|
||||||
|
|
||||||
|
// returns a console variable by name
|
||||||
|
consvar_t *CV_FindVar(const char *name);
|
||||||
|
|
||||||
// sets changed to 0 for every console variable
|
// sets changed to 0 for every console variable
|
||||||
void CV_ClearChangedFlags(void);
|
void CV_ClearChangedFlags(void);
|
||||||
|
|
||||||
|
|
|
@ -427,6 +427,26 @@ static int lib_cvRegisterVar(lua_State *L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int lib_cvFindVar(lua_State *L)
|
||||||
|
{
|
||||||
|
consvar_t *cv;
|
||||||
|
if (( cv = CV_FindVar(luaL_checkstring(L,1)) ))
|
||||||
|
{
|
||||||
|
lua_settop(L,1);/* We only want one argument in the stack. */
|
||||||
|
lua_pushlightuserdata(L, cv);/* Now the second value on stack. */
|
||||||
|
luaL_getmetatable(L, META_CVAR);
|
||||||
|
/*
|
||||||
|
The metatable is the last value on the stack, so this
|
||||||
|
applies it to the second value, which is the cvar.
|
||||||
|
*/
|
||||||
|
lua_setmetatable(L,2);
|
||||||
|
lua_pushvalue(L,2);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// CONS_Printf for a single player
|
// CONS_Printf for a single player
|
||||||
// Use 'print' in baselib for a global message.
|
// Use 'print' in baselib for a global message.
|
||||||
static int lib_consPrintf(lua_State *L)
|
static int lib_consPrintf(lua_State *L)
|
||||||
|
@ -466,6 +486,7 @@ static luaL_Reg lib[] = {
|
||||||
{"COM_BufAddText", lib_comBufAddText},
|
{"COM_BufAddText", lib_comBufAddText},
|
||||||
{"COM_BufInsertText", lib_comBufInsertText},
|
{"COM_BufInsertText", lib_comBufInsertText},
|
||||||
{"CV_RegisterVar", lib_cvRegisterVar},
|
{"CV_RegisterVar", lib_cvRegisterVar},
|
||||||
|
{"CV_FindVar", lib_cvFindVar},
|
||||||
{"CONS_Printf", lib_consPrintf},
|
{"CONS_Printf", lib_consPrintf},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue