lua-users home
lua-l archive

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


> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
> Behalf Of Philipp Kraus
> Sent: vrijdag 7 december 2012 13:35
> 
> Hello,
> 
> I'm using lua_register to register some C function. I can call them in my
Lua
> script. I would like to build packages, something like:
> mypackage.mysubpackage.myfunction The functions (functionpointers) read
> from a DLL, so I know the name of the package, subpackage and the pointer
> of the function. How can I build the package structure?
> Can I add the packagename to the lua_register eg lua_register(L,
> "package.subpackage.myfunction", funcptr) ?
> 
> Thanks
> 
> Phil

Not sure what you mean by packages, but if you mean nested functions in
table structures. Then you can just create a table.
Registering takes a table with names and values. The values can also be
sub-tables, just push a table on the stack.

See https://github.com/Tieske/LuaUPnP/blob/master/lib_src/LuaUPnP.c#L1073
here it creates an 'UPnP' table with three subtables; 'web', 'http', 'util',
and then registers a list of c functions in each of those.

Hth
Thijs