[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaJIT2 beta6: a little mess in error backtrace
- From: Mike Pall <mikelu-1103@...>
- Date: Mon, 14 Mar 2011 15:26:07 +0100
Arseny Vakhrushev wrote:
> return function (x)
> return bit.band(x)
> end
You're seeing an implementation difference. Replace bit.band with
a plain Lua function that triggers an error and you'll see.
Lua only resolves tail calls to Lua functions early. Tail calls to
C functions are actually handled like a regular call (i.e. the
stack grows!).
OTOH LuaJIT 2.x always resolves tail calls early for all kinds of
functions. I'd say this is more consistent.
> $ lua t.lua
> lua: t.lua:6: bad argument #1 to 'band' (number expected, got nil)
> stack traceback:
> [C]: in function 'band'
> t.lua:6: in function 'f'
> t.lua:11: in main chunk
> [C]: ?
>
> $ luajit-2.0.0-beta6 t.lua
> luajit-2.0.0-beta6: t.lua:11: bad argument #1 to 'f' (number expected, got nil)
> stack traceback:
> [C]: in function 'f'
> t.lua:11: in main chunk
> [C]: ?
>
> Please note the wrong function name in the argument misuse message.
The name is not wrong. The function name is inferred from the
stack that remains. If a real tail call happened, then the main
chunk is the next outer frame. And 'f' is the correct name for the
function which was invoked there.
[
You have to realize that both Lua and LuaJIT simply don't know the
name you gave a function in some module or wherever. They only
infer the name from the surrounding code of the caller. This works
out most of the time, but may get confusing in certain cases, e.g.:
local foo = math.sin
foo()
lua: test.lua:2: bad argument #1 to 'foo' (number expected, got no value)
stack traceback:
[C]: in function 'foo' <---- no mention of math.sin!
test.lua:2: in main chunk
[C]: ?
]
--Mike