[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Retrieve name of called function ?
- From: Markus Ewald <Markus_Ewald@...>
- Date: Mon, 11 Mar 2002 18:37:49 +0100
Luiz Henrique de Figueiredo wrote:
Is the function name from the call still somewhere in the lua stack or
can I somehow else retrieve the function name under which it was called ?
If you register the same C function with different names in Lua, they are
actually different objects in Lua and you can use the debug interface to find
the name it was registered. Try this:
static int F(lua_State *L)
{
lua_Debug ar;
lua_getstack(L,0,&ar);
lua_getinfo(L,"n",&ar);
printf("F called as %s\n",ar.name);
return 0;
}
lua_register(L,"F",F);
lua_register(L,"G",F);
That works, thanks!
However, with the following code
a = MyFunction
a("Test)
lua_getinfo() of course returns "a", not "MyFunction".
This isn't too important for the moment, but it means that any method
calls to functions stored in anything other than their matching name
variables will fail. On the other side, maybe I could create proxy
functions for each possible method call dynamically somehow (now this
will fool the debugger! :)
--lhf
Thx,
-Markus-