lua-users home
lua-l archive

Re: Lua 5 stack traceback / unwind

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


In lua 5, we are using luaL_loadbuffer followed by lua_pcall. If there
is an error, there is no stack trace back.
How do we implement this in lua 5?
Have a look at debug.traceback, it is also stored under the global name _TRACEBACK (in 5.0.2 at least, didn't check 5.1). You can provide it as an error handler in lua_pcall something like this:
 /* stack layout: func arg1 ... argn */
 /* provide traceback function */
 lua_pushstring(L, "_TRACEBACK");
 lua_gettable(L, LUA_GLOBALSINDEX);
 lua_insert(L, -n - 2);
 /* stack layout: _TRACEBACK func arg1 ... argn */
 /* call func with error handler */
 if (lua_pcall(L, n, 0, -n - 2))
 {
 /* an error with stack traceback is now at tos */
 }
The traceback function will still be on the stack after lua_pcall.
--
Wim

AltStyle によって変換されたページ (->オリジナル) /