lua-users home
lua-l archive

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


I just observed that currently, tracebacks are 'shortened' based on
the 'level' passed.

local function deep(lvl, ...)
    if lvl == 0 then
        print(debug.traceback(...))
        return
    end
    deep(lvl-1, ...)
end
deep(40, "my message", tonumber(arg[1]))


$ lua traceback-test.lua 1
my message
stack traceback:
traceback-test.lua:3: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
...
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in local 'deep'
traceback-test.lua:8: in main chunk
[C]: in ?

$ lua traceback-test.lua 9
my message
stack traceback:
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
...
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in upvalue 'deep'
traceback-test.lua:6: in local 'deep'
traceback-test.lua:8: in main chunk
[C]: in ?


Notice that the bit before the "..." gets shorter as you provide a
higher level argument.
This makes it hard to transparently wrap error producing functions,
as the amount of wrapping you do will effect the usefulness of the traceback

The fix should be simple enough: change luaL_traceback (
http://www.lua.org/source/5.3/lauxlib.c.html#luaL_traceback )
to calculate the `mark` based on the `level` argument.