I am making my own game engine, using Lua C API. I got such Lua table hierarchy:
my_lib = {
system = { ... },
keyboard = { ... },
graphics = { ... },
...
}
Also I got some C function, I want to register, something like that:
inline static int lua_mylib_do_cool_things(lua_State *L) {
mylib_do_cool_things(luaL_checknumber(L, 1));
return 0;
}
So, how can I register it like member of my_lib sub-table, just like that?
my_lib = {
system = { do_cool_things, ... },
keyboard = { ... }
graphics = { ...}
}
Now I only know the way to register members of global tables, it works like that:
inline void mylib_registerFuncAsTMem(const char *table, lua_CFunction func, const char *index) {
lua_getglobal(mylib_luaState, table);
lua_pushstring(mylib_luaState, index);
lua_pushcfunction(mylib_luaState, func);
lua_rawset(mylib_luaState, -3);
}
But what about sub-tables?