lua-users home
lua-l archive

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


RE: Registering a C function into a Lua table> (at least in old versions)
lua_settable expects a table as first
> argument, rather than a string.

It's just that I didn't know how to get the table State onto the stack. But,
I do now, because Asko Kauppi told me how.

Thanks, Vincent and Asko, I managed to get things working. :) I did this by
adding a single line of code, making my "register Lua function" code look
like this:

...
void State::Register(Method method, const char* module, const char* name)
{
    lua_pushstring(L, module);
    lua_gettable(L, LUA_GLOBALSINDEX);    // < new line
    lua_pushstring(L, name);
    lua_pushcfunction(L, method);
    lua_settable(L, 1);
    lua_pop(L, 1);
}
...

Thanks again!

Nick