[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: c side package creation
- From: Philipp Kraus <philipp.kraus@...>
- Date: Sat, 8 Dec 2012 12:22:30 +0100
Am 08.12.2012 um 04:43 schrieb Sean Conner:
> It was thus said that the Great Philipp Kraus once stated:
>> 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) ?
>
> Yes. From some modules I've written [1]:
>
> static const struct luaL_Reg reg_math[] =
> {
> { "randomseed" , math_randomseed },
> { "idiv" , math_idiv },
> { "div" , math_div },
> { NULL , NULL }
> };
>
> int luaopen_org_conman_math(lua_State *L)
> {
> luaL_register(L,"org.conman.math",reg_math);
> return 1;
> }
>
> Never had a problem.
>
> -spc
>
> [1] https://github.com/spc476/lua-conmanorg
You have got a static struct, but I have got a dynamic structure, that is called n-times like
luareg.register( functionname, functionpointer )
So the register is called n-times and should register the function on the Lua state. Can I overwrite
existing function? I found the luaL_newlibtable & luaL_newlib in both ways it creates a new table.
If I use it with equal data two times, overwrite the call the existing table?
Thanks
Phil