In a game that uses Lua for extensibility, when an error is thrown in a script, I'd like to show the user an error log, i.e. an error message and a stack trace, somewhat like this:
if (lua_pcall(L, nargs, nresults, 0) != 0) log.printline(lua_tostring(L, -1));
This only prints the error message, though, not the call stack.
I am aware I could use debug.traceback
, i.e. grabbing the function from the debug table through the API and then calling it, but I don't want to load the debug table at all because of security concerns, i.e. allowing a malicious user to write scripts that screw with the system and other global tables. (For the same reason I don't load io
and instead expose my own functions.)
I'm not using a bridge of any sort, I use the Lua API directly, through P/Invoke.
How would I go about printing a stack trace following a failed lua_pcall
call, without having to expose the debug table to the end user?