Merge COM_SAFE with other COM flags

Renames COM_SAFE to COM_LUA.
This commit is contained in:
James R 2023-03-15 11:57:39 -07:00
parent ff0f6e9b74
commit 0405df1a47
3 changed files with 16 additions and 18 deletions

View file

@ -109,6 +109,7 @@ static cmdalias_t *com_alias; // aliases list
// ========================================================================= // =========================================================================
static vsbuf_t com_text; // variable sized buffer static vsbuf_t com_text; // variable sized buffer
static com_flags_t com_flags = 0;
/** Purges control characters out of some text. /** Purges control characters out of some text.
* *
@ -141,7 +142,7 @@ COM_Purge (char *s, int *np)
* \param ptext The text to add. * \param ptext The text to add.
* \sa COM_BufInsertTextEx * \sa COM_BufInsertTextEx
*/ */
void COM_BufAddTextEx(const char *ptext, int flags) void COM_BufAddTextEx(const char *ptext, com_flags_t flags)
{ {
int l; int l;
char *text; char *text;
@ -164,7 +165,7 @@ void COM_BufAddTextEx(const char *ptext, int flags)
* \param ptext The text to execute. A newline is automatically added. * \param ptext The text to execute. A newline is automatically added.
* \sa COM_BufAddTextEx * \sa COM_BufAddTextEx
*/ */
void COM_BufInsertTextEx(const char *ptext, int flags) void COM_BufInsertTextEx(const char *ptext, com_flags_t flags)
{ {
const INT32 old_wait = com_wait; const INT32 old_wait = com_wait;
@ -320,7 +321,6 @@ static size_t com_argc;
static char *com_argv[MAX_ARGS]; static char *com_argv[MAX_ARGS];
static const char *com_null_string = ""; static const char *com_null_string = "";
static char *com_args = NULL; // current command args or NULL static char *com_args = NULL; // current command args or NULL
static int com_flags;
static void Got_NetVar(UINT8 **p, INT32 playernum); static void Got_NetVar(UINT8 **p, INT32 playernum);
@ -1124,7 +1124,7 @@ void VS_Write(vsbuf_t *buf, const void *data, size_t length)
M_Memcpy(VS_GetSpace(buf, length), data, length); M_Memcpy(VS_GetSpace(buf, length), data, length);
} }
void VS_WriteEx(vsbuf_t *buf, const void *data, size_t length, int flags) void VS_WriteEx(vsbuf_t *buf, const void *data, size_t length, com_flags_t flags)
{ {
char *p; char *p;
p = VS_GetSpace(buf, 2 + length); p = VS_GetSpace(buf, 2 + length);
@ -2472,7 +2472,7 @@ void CV_SaveVariables(FILE *f)
static boolean CV_Immutable(const consvar_t *var) static boolean CV_Immutable(const consvar_t *var)
{ {
// Currently operating from Lua // Currently operating from Lua
if (com_flags & COM_SAFE) if (com_flags & COM_LUA)
{ {
if (!(var->flags & CV_ALLOWLUA)) if (!(var->flags & CV_ALLOWLUA))
{ {

View file

@ -20,19 +20,17 @@
// Command buffer & command execution // Command buffer & command execution
//=================================== //===================================
/* Lua command registration flags. */ /* Command registration flags. */
enum typedef enum
{ {
COM_ADMIN = 1, COM_ADMIN = 1,
COM_SPLITSCREEN = 2, COM_SPLITSCREEN = 2,
COM_LOCAL = 4, COM_LOCAL = 4,
};
/* Command buffer flags. */ // COM_BufInsertText etc: can only access cvars
enum // with CV_ALLOWLUA set.
{ COM_LUA = 8,
COM_SAFE = 1, } com_flags_t;
};
typedef void (*com_func_t)(void); typedef void (*com_func_t)(void);
@ -53,11 +51,11 @@ const char *COM_CompleteAlias(const char *partial, INT32 skips);
// insert at queu (at end of other command) // insert at queu (at end of other command)
#define COM_BufAddText(s) COM_BufAddTextEx(s, 0) #define COM_BufAddText(s) COM_BufAddTextEx(s, 0)
void COM_BufAddTextEx(const char *btext, int flags); void COM_BufAddTextEx(const char *btext, com_flags_t flags);
// insert in head (before other command) // insert in head (before other command)
#define COM_BufInsertText(s) COM_BufInsertTextEx(s, 0) #define COM_BufInsertText(s) COM_BufInsertTextEx(s, 0)
void COM_BufInsertTextEx(const char *btext, int flags); void COM_BufInsertTextEx(const char *btext, com_flags_t flags);
// don't bother inserting, just do immediately // don't bother inserting, just do immediately
void COM_ImmedExecute(const char *ptext); void COM_ImmedExecute(const char *ptext);
@ -89,7 +87,7 @@ void VS_Free(vsbuf_t *buf);
void VS_Clear(vsbuf_t *buf); void VS_Clear(vsbuf_t *buf);
void *VS_GetSpace(vsbuf_t *buf, size_t length); void *VS_GetSpace(vsbuf_t *buf, size_t length);
void VS_Write(vsbuf_t *buf, const void *data, size_t length); void VS_Write(vsbuf_t *buf, const void *data, size_t length);
void VS_WriteEx(vsbuf_t *buf, const void *data, size_t length, int flags); void VS_WriteEx(vsbuf_t *buf, const void *data, size_t length, com_flags_t flags);
void VS_Print(vsbuf_t *buf, const char *data); // strcats onto the sizebuf void VS_Print(vsbuf_t *buf, const char *data); // strcats onto the sizebuf
//================== //==================

View file

@ -253,7 +253,7 @@ static int lib_comBufAddText(lua_State *L)
plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
if (plr && plr != &players[consoleplayer]) if (plr && plr != &players[consoleplayer])
return 0; return 0;
COM_BufAddTextEx(va("%s\n", luaL_checkstring(L, 2)), COM_SAFE); COM_BufAddTextEx(va("%s\n", luaL_checkstring(L, 2)), COM_LUA);
return 0; return 0;
} }
@ -269,7 +269,7 @@ static int lib_comBufInsertText(lua_State *L)
plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
if (plr && plr != &players[consoleplayer]) if (plr && plr != &players[consoleplayer])
return 0; return 0;
COM_BufInsertTextEx(va("%s\n", luaL_checkstring(L, 2)), COM_SAFE); COM_BufInsertTextEx(va("%s\n", luaL_checkstring(L, 2)), COM_LUA);
return 0; return 0;
} }