@@ -112,12 +112,12 @@ void COM_Lua_f(void)
112112
113113 lua_rawgeti (gL , -1 , 2 ); // push flags from command info table
114114 if (lua_isboolean (gL , -1 ))
115- flags = (lua_toboolean (gL , -1 ) ? 1 : 0 );
115+ flags = (lua_toboolean (gL , -1 ) ? COM_ADMIN : 0 );
116116 else
117117 flags = (UINT8 )lua_tointeger (gL , -1 );
118118 lua_pop (gL , 1 ); // pop flags
119119
120- if (flags & 2 ) // flag 2: splitscreen player command.
120+ if (flags & COM_SPLITSCREEN ) // flag 2: splitscreen player command. TODO: support 4P
121121 {
122122 if (!splitscreen )
123123 {
@@ -127,7 +127,7 @@ void COM_Lua_f(void)
127127 playernum = secondarydisplayplayer ;
128128 }
129129
130- if (netgame )
130+ if (netgame && !( flags & COM_LOCAL )) /* don't send local commands */
131131 { // Send the command through the network
132132 UINT8 argc ;
133133 lua_pop (gL , 1 ); // pop command info table
@@ -186,7 +186,15 @@ static int lib_comAddCommand(lua_State *L)
186186 if (lua_gettop (L ) >= 3 )
187187 { // For the third argument, only take a boolean or a number.
188188 lua_settop (L , 3 );
189- if (lua_type (L , 3 ) != LUA_TBOOLEAN )
189+ if (lua_type (L , 3 ) == LUA_TBOOLEAN )
190+ {
191+ CONS_Alert (CONS_WARNING ,
192+ "Using a boolean for admin commands is "
193+ "deprecated.\n"
194+ "Use \"COM_ADMIN\" instead.\n"
195+ );
196+ }
197+ else
190198 luaL_checktype (L , 3 , LUA_TNUMBER );
191199 }
192200 else
@@ -421,6 +429,46 @@ static int lib_cvRegisterVar(lua_State *L)
421429 return 1 ;
422430}
423431
432+ static int CVarSetFunction
433+ (
434+ lua_State * L ,
435+ void (* Set )(consvar_t * , const char * ),
436+ void (* SetValue )(consvar_t * , INT32 )
437+ ){
438+ consvar_t * cvar = (consvar_t * )luaL_checkudata (L , 1 , META_CVAR );
439+
440+ switch (lua_type (L , 2 ))
441+ {
442+ case LUA_TSTRING :
443+ (* Set )(cvar , lua_tostring (L , 2 ));
444+ break ;
445+ case LUA_TNUMBER :
446+ (* SetValue )(cvar , (INT32 )lua_tonumber (L , 2 ));
447+ break ;
448+ default :
449+ return luaL_typerror (L , 1 , "string or number" );
450+ }
451+
452+ return 0 ;
453+ }
454+
455+ static int lib_cvSet (lua_State * L )
456+ {
457+ return CVarSetFunction (L , CV_Set , CV_SetValue );
458+ }
459+
460+ static int lib_cvStealthSet (lua_State * L )
461+ {
462+ return CVarSetFunction (L , CV_StealthSet , CV_StealthSetValue );
463+ }
464+
465+ static int lib_cvAddValue (lua_State * L )
466+ {
467+ consvar_t * cvar = (consvar_t * )luaL_checkudata (L , 1 , META_CVAR );
468+ CV_AddValue (cvar , (INT32 )luaL_checknumber (L , 2 ));
469+ return 0 ;
470+ }
471+
424472// CONS_Printf for a single player
425473// Use 'print' in baselib for a global message.
426474static int lib_consPrintf (lua_State * L )
@@ -459,6 +507,9 @@ static luaL_Reg lib[] = {
459507 {"COM_BufAddText" , lib_comBufAddText },
460508 {"COM_BufInsertText" , lib_comBufInsertText },
461509 {"CV_RegisterVar" , lib_cvRegisterVar },
510+ {"CV_Set" , lib_cvSet },
511+ {"CV_StealthSet" , lib_cvStealthSet },
512+ {"CV_AddValue" , lib_cvAddValue },
462513 {"CONS_Printf" , lib_consPrintf },
463514 {NULL , NULL }
464515};
0 commit comments