From 5f4d6c4545d5372ae5b291c6b9134d6140b2c925 Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Fri, 8 Nov 2019 22:13:50 -0300 Subject: [PATCH] Avoid running setter metamethods when not appropriate to do so --- src/lua_infolib.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/lua_infolib.c b/src/lua_infolib.c index 5be036a8f..4cb851dca 100644 --- a/src/lua_infolib.c +++ b/src/lua_infolib.c @@ -362,6 +362,11 @@ static int lib_setSpriteInfo(lua_State *L) { spriteinfo_t *info; + if (!lua_lumploading) + return luaL_error(L, "Do not alter spriteinfo_t from within a hook or coroutine!"); + if (hud_running) + return luaL_error(L, "Do not alter spriteinfo_t in HUD rendering code!"); + lua_remove(L, 1); { UINT32 i = luaL_checkinteger(L, 1); @@ -373,11 +378,6 @@ static int lib_setSpriteInfo(lua_State *L) lua_remove(L, 1); // pop sprite num, don't need it any more. lua_settop(L, 1); // cut the stack here. the only thing left now is the table of data we're assigning to the spriteinfo. - if (!lua_lumploading) - return luaL_error(L, "Do not alter spriteinfo_t from within a hook or coroutine!"); - if (hud_running) - return luaL_error(L, "Do not alter spriteinfo_t in HUD rendering code!"); - lua_pushnil(L); while (lua_next(L, 1)) { lua_Integer i = 0; @@ -527,6 +527,11 @@ static int pivotlist_set(lua_State *L) const char *field = luaL_checkstring(L, 2); UINT8 frame; + if (!lua_lumploading) + return luaL_error(L, "Do not alter spriteframepivot_t from within a hook or coroutine!"); + if (hud_running) + return luaL_error(L, "Do not alter spriteframepivot_t in HUD rendering code!"); + I_Assert(pivotlist != NULL); frame = R_Char2Frame(field[0]); @@ -574,6 +579,11 @@ static int framepivot_set(lua_State *L) spriteframepivot_t *framepivot = *((spriteframepivot_t **)luaL_checkudata(L, 1, META_FRAMEPIVOT)); const char *field = luaL_checkstring(L, 2); + if (!lua_lumploading) + return luaL_error(L, "Do not alter spriteframepivot_t from within a hook or coroutine!"); + if (hud_running) + return luaL_error(L, "Do not alter spriteframepivot_t in HUD rendering code!"); + I_Assert(framepivot != NULL); if (fastcmp("x", field))