lua-users home
lua-l archive

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


>>> [...] It used to be the
>>> case that debug.traceback was triggered by Lua before the error was
>>> thrown, which allowed for some access to Lua state, but it's no longer
>>> the case with Lua 5.2+.
>> I don't think that changed in Lua 5.2.
> The default Lua interpreter in Lua 5.1 calls `debug.traceback` in the
> message handler, while Lua 5.2/3 use `luaL_traceback` instead.
> `debug.traceback` is easier to monkey-patch ...

Exactly; the following script prints "traceback
...\traceback.lua:2: fails here    2" in Lua 5.1, but throws a
"normal" error in Lua 5.2+

debug.traceback = function(...) print("traceback", ...) end
error("fails here")

The user could also modify the error by returning appropriate result
from debug.traceback.

Paul.