From 1747ebf481fab9e30d69aee23df7e59a9ec52d60 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 2 Jun 2024 00:43:09 +0300 Subject: [PATCH] Lua_optoption shouldn't change stack state at the end of call now --- src/lua_script.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lua_script.c b/src/lua_script.c index 381448e72..13cdf7bdf 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1680,6 +1680,8 @@ void LUA_UnArchiveDemo(void) // For mobj_t, player_t, etc. to take custom variables. int Lua_optoption(lua_State *L, int narg, int def, int list_ref) { + int result = -1; + if (lua_isnoneornil(L, narg)) return def; @@ -1692,8 +1694,11 @@ int Lua_optoption(lua_State *L, int narg, int def, int list_ref) lua_rawget(L, -2); if (lua_isnumber(L, -1)) - return lua_tointeger(L, -1); - return -1; + result = lua_tointeger(L, -1); + + lua_pop(L, 2); // Pop result and fields table + + return result; } @@ -1710,4 +1715,4 @@ int Lua_CreateFieldTable(lua_State *L, const char *const lst[]) } return luaL_ref(L, LUA_REGISTRYINDEX); -} \ No newline at end of file +}