lua-users home
lua-l archive

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


>Lua' debug is confusing the hell out of me, currently I have this:
>
>if (lua_pcall(L, 2, 1, 0) != 0)
>{
>lua_pushstring(L,"doerror");
>lua_gettable(L, LUA_GLOBALSINDEX);
>lua_call(L, 0, 0);
>}

If you don't supply a error handler when calling lua_pcall, then you
cannot get a traceback *after* the error has occurred because Lua has
wound its stack.

Try:

lua_pushliteral(L, "traceback");
lua_gettable(L, LUA_DBLIBNAME);
... push your function
... push arg 1
... push arg 2
if (lua_pcall(L, 2, 1, -4) != 0)
... do something with the traceback, which is at the top of the stack.
... for instance, print lua_tostring(L,-1).

>function doerror()
>debug.traceback()
>end

You need "return debug.traceback()", but like I said, there's not point
in calling this after lua_pcall has returned.
--lhf