Rename CV_NOLUA to CV_ALLOWLUA, opt IN to Lua mutability

This commit is contained in:
James R 2023-03-15 11:43:53 -07:00
parent a39f69c9c7
commit 5d08bfd706
5 changed files with 24 additions and 6 deletions

View file

@ -57,6 +57,7 @@ static boolean CV_FilterVarByVersion(consvar_t *v, const char *valstr);
static boolean CV_Command(void);
consvar_t *CV_FindVar(const char *name);
static const char *CV_StringValue(const char *var_name);
static boolean CV_Immutable(const consvar_t *var);
static consvar_t *consvar_vars; // list of registered console variables
static UINT16 consvar_number_of_netids = 0;
@ -2371,7 +2372,7 @@ static boolean CV_Command(void)
if (!v)
return false;
if (( com_flags & COM_SAFE ) && ( v->flags & CV_NOLUA ))
if (CV_Immutable(v))
{
CONS_Alert(CONS_WARNING, "Variable '%s' cannot be changed from Lua.\n", v->name);
return true;
@ -2460,6 +2461,22 @@ void CV_SaveVariables(FILE *f)
}
}
// Returns true if this cvar cannot be modified in current context.
// Such as if the cvar does not have CV_ALLOWLUA.
static boolean CV_Immutable(const consvar_t *var)
{
// Currently operating from Lua
if (com_flags & COM_SAFE)
{
if (!(var->flags & CV_ALLOWLUA))
{
return true;
}
}
return false;
}
//============================================================================
// SCRIPT PARSE
//============================================================================

View file

@ -120,7 +120,7 @@ typedef enum
// can only be set when we have the pointer to it
// used on menus
CV_CHEAT = 2048, // Don't let this be used in multiplayer unless cheats are on.
CV_NOLUA = 4096,/* don't let this be called from Lua */
CV_ALLOWLUA = 4096,/* Let this be called from Lua */
} cvflags_t;
typedef struct CV_PossibleValue_s

View file

@ -5525,7 +5525,7 @@ struct int_const_s const INT_CONST[] = {
{"CV_HIDEN",CV_HIDEN},
{"CV_HIDDEN",CV_HIDEN},
{"CV_CHEAT",CV_CHEAT},
{"CV_NOLUA",CV_NOLUA},
{"CV_ALLOWLUA",CV_ALLOWLUA},
// v_video flags
{"V_NOSCALEPATCH",V_NOSCALEPATCH},

View file

@ -450,6 +450,7 @@ static int lib_cvRegisterVar(lua_State *L)
return luaL_error(L, M_GetText("Variable %s has CV_CALL without a function"), cvar->name);
}
cvar->flags |= CV_ALLOWLUA;
// actually time to register it to the console now! Finally!
cvar->flags |= CV_MODIFIED;
CV_RegisterVar(cvar);
@ -478,7 +479,7 @@ static int CVarSetFunction
){
consvar_t *cvar = *(consvar_t **)luaL_checkudata(L, 1, META_CVAR);
if (cvar->flags & CV_NOLUA)
if (!(cvar->flags & CV_ALLOWLUA))
return luaL_error(L, "Variable '%s' cannot be set from Lua.", cvar->name);
switch (lua_type(L, 2))
@ -510,7 +511,7 @@ static int lib_cvAddValue(lua_State *L)
{
consvar_t *cvar = *(consvar_t **)luaL_checkudata(L, 1, META_CVAR);
if (cvar->flags & CV_NOLUA)
if (!(cvar->flags & CV_ALLOWLUA))
return luaL_error(L, "Variable %s cannot be set from Lua.", cvar->name);
CV_AddValue(cvar, (INT32)luaL_checknumber(L, 2));

View file

@ -82,7 +82,7 @@ CV_PossibleValue_t cv_renderer_t[] = {
{0, NULL}
};
consvar_t cv_renderer = CVAR_INIT ("renderer", "Software", CV_SAVE|CV_NOLUA|CV_CALL, cv_renderer_t, SCR_ChangeRenderer);
consvar_t cv_renderer = CVAR_INIT ("renderer", "Software", CV_SAVE|CV_CALL, cv_renderer_t, SCR_ChangeRenderer);
static void SCR_ChangeFullscreen(void);