@@ -710,30 +710,32 @@ bool CScriptEngine::ExecuteLua (DISPID & dispid, // dispatch ID, will b
710
710
} // end of CScriptEngine::ExecuteLua
711
711
712
712
713
+ // bugfix thanks to Twisol (previous version didn't handle bad debug table properly)
713
714
void GetTracebackFunction (lua_State *L)
714
715
{
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);
717
718
718
- if (!lua_istable (L, -1 ))
719
+ // if it is a table then find traceback function
720
+ if (lua_istable (L, -1 ))
719
721
{
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 );
724
726
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 ;
734
730
}
735
731
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
+
737
739
}
738
740
739
741
int CallLuaWithTraceBack (lua_State *L, const int iArguments, const int iReturn)
0 commit comments