[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: lua_getinfo(L,"n",&ar) doesn't use upvals to guess function name?
- From: Tim Gogolin <tgogolin@...>
- Date: Thu, 18 Mar 2004 10:40:35 -0600
I understand that lua functions don't have names and that lua_getinfo()
is just running a series of (possibly expensive) searches to find a
"reasonable" name for the current function... for example, search the
environment for a key whose value is the current function, etc.
But sometimes lua_getinfo() is returning nil for the name when I would
have expected it to be able to guess the name. When the function is
called as an upvalue for example. Here is a simplified version of what
I am seeing:
local function foo()
my_dump_lua_stack_in_C() -- should print the name of this function as
local function bar()
return foo() -- can call "foo", because foo is an upvalue here
-- export bar somehow and somebody calls it
Is my understanding correct that lua_getinfo(L,"n",&ar) does not look
at the previous stack frame's upvalues when guessing a "name" for the
function? If so, is there any reason why not? Is the previous
activation record not easily findable from inside lua_getinfo()?
My workaround for this will be to query the calling 'ar' myself and
search the named upvals (if getinfo fails to find the name through the
normal mechanism). Is there any reason why this is a bad idea?