lua-users home
lua-l archive

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


Is there possible to get the function name (lua object) in the
functionC scope when a Lua call is invoked to a Cfunction?

I registered 2 CFunctions (same static int lua_CFunction(..) but
different objects in Lua)

static int luaCFunc( lua_State *L);

lua_pushcfunction( _sLUA, luaCFunc );
lua_setglobal( _sLUA, "test1" );

lua_pushcfunction( _sLUA, luaCFunc );
lua_setglobal( _sLUA, "test2" );

I tested the functions objects on Lua:

print(type(test1))
print(type(test2))
print(test1)
print(test2)

and it seems ok.

I noticed that they pointed to the same C func *, as expected:

fnC = lua_tocfuntion( _sLua, -1 );

fnC is the same for the 2 objects.

Is there any way that I can receive or get the Lua object name that
stored and called the function?

Any one when called, test1 or test2, the same CFunction will be
invoked, but is possible to know the Lua Object name?

My objective is to create a common static lua_CFunction for all
registered functions and dispach to the correct object based on the
function name<->C++object. Some thing like MFC does with WndProc(..)
on windows.

Thanks,

Guilherme