Skip to content

Commit 347fdc1

Browse files
committed
Fixed bug in GetTracebackFunction
1 parent 0f2d70c commit 347fdc1

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

scripting/lua_scripting.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -710,30 +710,32 @@ bool CScriptEngine::ExecuteLua (DISPID & dispid, // dispatch ID, will b
710710
} // end of CScriptEngine::ExecuteLua
711711

712712

713+
// bugfix thanks to Twisol (previous version didn't handle bad debug table properly)
713714
void GetTracebackFunction (lua_State *L)
714715
{
715-
lua_pushliteral (L, LUA_DBLIBNAME); // "debug"
716-
lua_rawget (L, LUA_GLOBALSINDEX); // get debug library
716+
// get debug table
717+
lua_getfield (L, LUA_GLOBALSINDEX, LUA_DBLIBNAME);
717718

718-
if (!lua_istable (L, -1))
719+
// if it is a table then find traceback function
720+
if (lua_istable (L, -1))
719721
{
720-
lua_pop (L, 2); // pop result and debug table
721-
lua_pushnil (L);
722-
return;
723-
}
722+
lua_getfield (L, -1, "traceback");
723+
724+
// remove debug table, leave traceback function
725+
lua_remove (L, -2);
724726

725-
// get debug.traceback
726-
lua_pushstring(L, "traceback");
727-
lua_rawget (L, -2); // get getinfo function
728-
729-
if (!lua_isfunction (L, -1))
730-
{
731-
lua_pop (L, 2); // pop result and debug table
732-
lua_pushnil (L);
733-
return;
727+
// if it is indeed a function, well and good
728+
if (lua_isfunction (L, -1))
729+
return;
734730
}
735731

736-
lua_remove (L, -2); // remove debug table, leave traceback function
732+
// not a table, or debug.traceback not a function, get rid of it
733+
lua_pop (L, 1);
734+
735+
// return nil to caller
736+
lua_pushnil (L);
737+
return;
738+
737739
}
738740

739741
int CallLuaWithTraceBack (lua_State *L, const int iArguments, const int iReturn)

0 commit comments

Comments
 (0)