From 286b316cf98722a6c80130fd1714370762aa2663 Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Mon, 1 Jun 2020 15:43:14 +0200 Subject: [PATCH] Fix dofile() return incorrect values --- src/lua_script.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lua_script.c b/src/lua_script.c index a0e4588a4..374294d6e 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -452,6 +452,8 @@ INT32 lua_lumploading = 0; // Load a script from a MYFILE static inline void LUA_LoadFile(MYFILE *f, char *name, boolean noresults) { + int errorhandlerindex; + if (!name) name = wadfiles[f->wad]->filename; CONS_Printf("Loading Lua script from %s\n", name); @@ -463,12 +465,13 @@ static inline void LUA_LoadFile(MYFILE *f, char *name, boolean noresults) lua_lumploading++; // turn on loading flag lua_pushcfunction(gL, LUA_GetErrorMessage); + errorhandlerindex = lua_gettop(gL); if (luaL_loadbuffer(gL, f->data, f->size, va("@%s",name)) || lua_pcall(gL, 0, noresults ? 0 : LUA_MULTRET, lua_gettop(gL) - 1)) { CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL,-1)); lua_pop(gL,1); } lua_gc(gL, LUA_GCCOLLECT, 0); - lua_pop(gL, 1); // Pop error handler + lua_remove(gL, errorhandlerindex); lua_lumploading--; // turn off again }