void lv_append_lib_funcs(lua_State *L, luaL_Reg * reg)
{
lua_getglobal(L, LV_LIB_NAME);
if ( ! lua_istable(L, -1)) {
luaL_newlib (L, reg);
lua_setglobal(L, LV_LIB_NAME);
return;
}
luaL_setfuncs(L, reg, 0);
}
That works, thanks a lot John.
On Sat, May 8, 2021 at 4:46 PM Varanda < m@varanda.ca> wrote: Hello All,
In my bindings I have a library created in C (using luaL_newlib)
Later on, In some situation, I would like to have another C code appending more functions into that existing library.
How can I do this only using C?
The resulting library is just an ordinary table containing functions, and luaL_newlib leaves that table on the top of the stack. Store a reference to that in the registry using luaL_ref and LUA_REGISTRYINDEX, then later you can fetch that table and use luaL_setfuncs again (luaL_newlib uses that function under the hood), or do it one at a time with the standard table manipulation functions.
|