lua-users home
lua-l archive

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

E. Wing wrote:
> I've been trying to use the Lua debug library to tell me what the
> current function name is. But I keep getting a blank/empty value. I
> had done this before with Lua 5.0, so I have created a simple test
> case. It seems that I do get the function name under Lua 5.0.3, but
> not under Lua 5.1.2.

Both Lua 5.0 and 5.1 try to infer function names for the debug
library by symbolic execution of Lua code in the previous
(calling) frame. Basically this works its way backwards from the
function slot to find a name for its origin. This works fine in
most cases, but not in yours, because you are calling it from C
code (i.e. no guess possible).

In this case only Lua 5.0 does some additional (expensive)
traversal of the globals table to find a matching entry. This
happens to work in your case because "f" is a global.

The extra code was dropped in Lua 5.1. Probably because it's both
expensive and useless in the general case. Most library functions
are in extra tables and any reasonably complex program does not
store functions in the globals table (hopefully).

[Please remember that debug.getinfo can be quite slow and is only
intended for debugging. It's not a programming technique.]