lua-users home
lua-l archive

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


>However, with the following code
>    a = MyFunction
>    a("Test)
>
>lua_getinfo() of course returns "a", not "MyFunction".

Like I said, it only works for functions that have only one name, that is,
that are the value of only a single global variable.
If "a" is local in the code above, it should work.

Anyway, for the record, the debug interface is not supposed to be used as
a general programming tool. In particular, finding the name of a value is a
costly operation.

A better solution is to register C closures instead of C functions, and
use the name as an upvalue. Something like this:

	lua_pushstring(L,"F"); lua_pushclosure(L,F,1); lua_setglobal(L,"F");
	lua_pushstring(L,"G"); lua_pushclosure(L,F,1); lua_setglobal(L,"G");

and then in F get the upvalue and do whatever you want.
--lhf