Original Post
Example: lua code
IWantToKnowTheNameOfThisFuncInC1("a string")
IWantToKnowTheNameOfThisFuncInC2("another string")
C code
//load up a script and register two different functions to point to
//the same translator function, in this case luaTranslator():
lua_register(L, "IWantToKnowTheNameOfThisFuncInC1", luaTranslator);
lua_register(L, "IWantToKnowTheNameOfThisFuncInC2", luaTranslator);
lua_pcall(L, 0, LUA_MULTRET, 0);
static int luaTranslator(lua_State *lua)
{
//<- this is where I need to know the name of the calling function,
//which is either IWantToKnowTheNameOfThisFuncInC1 or
//IWantToKnowTheNameOfThisFuncInC2. How can I do that?
}
I need the translator function to do type checking before calling the actual C function and only have one single place around where I do that. This also means I don't want a bunch of forwarding functions. Another big plus of having a single translator function is encapsulation.