From a47aea4c9f01b411372b95d28dfc57866ef6bb55 Mon Sep 17 00:00:00 2001 From: Indev Date: Fri, 8 Sep 2023 18:29:05 +0300 Subject: [PATCH] Fix 'error in error handling' for cases when error happens in cvar.func right when cvar is registered --- src/lua_consolelib.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index dc965851f..584fc2ef8 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -293,6 +293,8 @@ static void Lua_OnChange(void) //lua_settop(gL, 0); // Just in case... lua_pushcfunction(gL, LUA_GetErrorMessage); + int error_handler_i = abs_index(gL, -1); + // From CV_OnChange registry field, get the function for this cvar by name. lua_getfield(gL, LUA_REGISTRYINDEX, "CV_OnChange"); I_Assert(lua_istable(gL, -1)); @@ -304,7 +306,7 @@ static void Lua_OnChange(void) lua_getfield(gL, -1, cvname); // get consvar_t* userdata. lua_remove(gL, -2); // pop the CV_Vars table. - LUA_Call(gL, 1, 0, 1); // call function(cvar) + LUA_Call(gL, 1, 0, error_handler_i); // call function(cvar) lua_pop(gL, 2); // pop CV_OnChange table and error handler }