lua-users home
lua-l archive

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


On Fri, Oct 23, 2009 at 11:44 AM, Chris Gagnon <cgagnon@zindagigames.com> wrote:
> Ive experimented with this, however this doesn't seem to work likely since
> it's added to the metatable.

luaL_register() does two different things:

- if you set libname to NULL, it adds the C functions to the Lua table
currently on the stack's top

- if libname is not NULL, it creates a table, adds the C functions,
and stores the table in _G[libname] , and package.loaded[libname],
roughly what expected for a loadable module.


i usually use one luaL_Reg[] array for the module and one for the
metatable of each type i define.  if you want the functions to be
stored directly in the table (and not on a metatable) you can simply
do:

lua_newtable(L);
luaL_register (L, NULL, funcs);
return 1;

where 'funcs' is the luaL_Reg[] array.  just for this. (and a
different one for the metatables, i guess)

-- 
Javier