lua_register using const char * actionname, void(*action)()

Viewed 102

I have a lua_State ready to go with a script that will call actionname. Before the script is started an void(*action)() needs to be registered. This process is called by a client that does not have access to my lua_State nor does the client include lua. I can not change method signature to lua_CFunction because the client code will not know the definitions needet to provide that function.

I have to provide a function like this one here:

void registeraction(const char * actionname, void(*action)())
{
    struct functor
    {
        void(*action)();
        functor(void(*action)()) : action(action) {}
        int operator()(lua_State* state) { action(); return 0; }
    };
    functor callme{ action };
    lua_State * L = lua->ptr;
    const char * n = actionname;
    lua_CFunction f{ callme }; //no suitable conversion
    lua_register(L, n, f);
}

How can i wrap the action so I can shove it into Lua?

1 Answers
Related