lua-users home
lua-l archive

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


>>>>> "Francisco" == Francisco Olarte <folarte@peoplecall.com> writes:

 >> So, why in f2 the field 'name' is nil?

 Francisco> Mandatory tail call elimination? I get this, have not dug
 Francisco> more as I'm not too familiar with the expected returns:

getfuncname (at least in 5.4.2) includes this:

  /* calling function is a known Lua function? */
  else if (!(ci->callstatus & CIST_TAIL) && isLua(ci->previous))
    return funcnamefromcode(L, ci->previous, name);

Lua function values don't have any "name" property inherent to the
function; that is, the only "name" a function has is the name used to
refer to some location from which the function value was fetched (so a
function might have many names or none).

What getinfo does is try and look at the bytecode instructions of the
calling function to determine where it got the function value from. But
this is not possible if the caller was not Lua code, or if the call was
a tail call (since in the latter case there's no information about the
caller).

Notably, what luaL_traceback does is somewhat different (and likely much
slower): it first looks to see if the function value is found under a
string key in any table stored in package.loaded (actually
registry._LOADED but they are initially the same table), and only if it
is not does it use the name from debug.getinfo.

-- 
Andrew.