lua-users home
lua-l archive

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

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);
  luaL_setfuncs(L, reg, 0);

On May 8, 2021, at 7:16 PM, Varanda <> wrote:

That works, thanks a lot John.

On May 8, 2021, at 5:05 PM, Jonathan Goble <> wrote:

On Sat, May 8, 2021 at 4:46 PM Varanda <> 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.