[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: luaL_argcheck doesn't know function name if debug.traceback isn't used?
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Fri, 24 Aug 2012 13:51:30 +0100
2012/8/23 Sam Roberts <vieuxtech@gmail.com>:
> I have a function that calls luaL_argcheck(), but when I call it with pcall:
>
> print(pcall(mylib.read, 2))
>
> I get:
>
> .... bad argument #2 to '?' (attempt to read past end of ready data)
>
> However, my top level call into lua (which uses the lua_pcall api and
> provides debug.traceback as its err handler), as well as local calls
> to xpcall:
>
> print(xpcall(function () mylib.read(2) end, debug.traceback))
>
> prints error msg strings with the function name:
>
> ... bad argument #2 to 'read'
>
> Is that just the nature of things, that if debug.traceback isn't
> called, information about function names on the stack aren't filled
> in, and argcheck can't know the calling function's name?
The problem is not in the use of traceback or not, but in the way the
function is called. in your first example, you pass an anonymous
function reference to pcall, and when that function is called it no
longer has a name. In the second example you do a simple call
generated by the compiler, which can pass along extra naming
information (I don't know exactly how that is done).
To show how it's unrelated to traceback, the following should show the
name of your function:
print(pcall(function() mylib.read(2) end))