lua-users home
lua-l archive

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


On 2011-03-14, at 17:26, Mike Pall wrote:

> 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]: ?
> ]
> 

That makes sense for me. But confusing error messages might appear in the following case (actually this is closer to the case I had in my code):

function f()
  return function(a, b, c)
    local x = nil
   return bit.band(x) -- no direct connection with a, b, c args here
  end
end

local func = f()
func(1, 2, 3) <--- error

So, in this case, I am notified that the first argument of the call to f(1, 2, 3) should be a number (and it actually is!), not nil which is a bit confusing. I can get used to it if can't be managed better.

// Seny