mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2025-01-13 05:11:01 +00:00
Expose CV_FindVar to Lua
This commit is contained in:
parent
2e5608d33b
commit
63eadaf83c
3 changed files with 30 additions and 2 deletions
|
@ -56,7 +56,7 @@ static void CV_EnforceExecVersion(void);
|
|||
static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr);
|
||||
|
||||
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 consvar_t *consvar_vars; // list of registered console variables
|
||||
|
||||
|
@ -1027,7 +1027,7 @@ static const char *cv_null_string = "";
|
|||
* \return Pointer to the variable if found, or NULL.
|
||||
* \sa CV_FindNetVar
|
||||
*/
|
||||
static consvar_t *CV_FindVar(const char *name)
|
||||
consvar_t *CV_FindVar(const char *name)
|
||||
{
|
||||
consvar_t *cvar;
|
||||
|
||||
|
|
|
@ -173,4 +173,7 @@ void CV_ResetCheatNetVars(void);
|
|||
boolean CV_IsSetToDefault(consvar_t *v);
|
||||
UINT8 CV_CheatsEnabled(void);
|
||||
|
||||
// Returns cvar by name. Exposed here for Lua.
|
||||
consvar_t *CV_FindVar(const char *name);
|
||||
|
||||
#endif // __COMMAND_H__
|
||||
|
|
|
@ -413,6 +413,30 @@ static int lib_cvRegisterVar(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
// For some reason I couldn't cherry pick this.
|
||||
// Credits for this function go to james. All hail birb. -Lat'
|
||||
|
||||
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
|
||||
// Use 'print' in baselib for a global message.
|
||||
static int lib_consPrintf(lua_State *L)
|
||||
|
@ -452,6 +476,7 @@ static luaL_Reg lib[] = {
|
|||
{"COM_BufInsertText", lib_comBufInsertText},
|
||||
{"CV_RegisterVar", lib_cvRegisterVar},
|
||||
{"CONS_Printf", lib_consPrintf},
|
||||
{"CV_FindVar", lib_cvFindVar},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue