From b49a3c6c7d8160e175993eee73cdf487260efc34 Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Sun, 20 Dec 2020 21:43:14 -0600 Subject: [PATCH] Have Lua_OnChange restore the stack to what it was before it was called. So we don't get Luas with access to LUA_GetErrorMessage. --- src/lua_consolelib.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index f148a8dcb..9da23bd39 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -293,11 +293,8 @@ static void Lua_OnChange(void) { /// \todo Network this! XD_LUAVAR - // Why?.. - //lua_settop(gL, 0); // Just in case... lua_pushcfunction(gL, LUA_GetErrorMessage); - - int error_handler_i = abs_index(gL, -1); + lua_insert(gL, 1); // Because LUA_Call wants it at index 1. // From CV_OnChange registry field, get the function for this cvar by name. lua_getfield(gL, LUA_REGISTRYINDEX, "CV_OnChange"); @@ -307,8 +304,9 @@ static void Lua_OnChange(void) LUA_RawPushUserdata(gL, this_cvar); - LUA_Call(gL, 1, 0, error_handler_i); // call function(cvar) - lua_pop(gL, 2); // pop CV_OnChange table and error handler + LUA_Call(gL, 1, 0, 1); // call function(cvar) + lua_pop(gL, 1); // pop CV_OnChange table + lua_remove(gL, 1); // remove LUA_GetErrorMessage } static int lib_cvRegisterVar(lua_State *L)