[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Trying to resolve name of a function inside an argument list
- From: "feigling" <feigling@...>
- Date: Sun, 7 Oct 2007 15:25:14 +0200
Hello,
I am trying to get the name of a function which is an argument of another
function. Here's a small example:
Lua script file contains:
##
function lua_func()
end
c_func(lua_func)
##
c_func is a function which I registered via lua_register(lua_state,
"c_func", lua_c_func);
Now I am trying to get the string "lua_func" in the lua_c_func() C-function.
When I was using Lua 5.0.2 I did it the following way:
##
int
lua_c_func(struct lua_State *lua_state)
{
lua_Debug ar;
if(!lua_isfunction(lua_state, 1))
{
printf("Argument not a func\n");
return 0;
}
lua_getinfo(lua_state, ">n", &ar);
printf("Name of function: %s\n", ar.name);
return 0;
}
##
which resulted in "Name of function: lua_func". After upgrading to Lua 5.1.2
it doesn't seem to work that way anymore. I tried to use lua_getinfo() in
several different ways and also tried the following:
##
int
lua_c_func(struct lua_State *lua_state)
{
lua_Debug ar;
if(!lua_isfunction(lua_state, 1))
{
printf("Argument not a func\n");
return 0;
}
if(!lua_getstack(lua_state, 0, &ar))
{
printf("Unable to execute lua_getstack()\n");
return 0;
}
printf("Name of function: %s\n", lua_getlocal(lua_state, &ar, 1));
return 0;
}
##
which resulted in "Name of function: (*temporary)" so now I am kinda
clueless.
Would be great if somebody could give me an advise.
Thanks in advance.