[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Wishlists and Modules (was [ANN] libmc)
- From: Duncan Cross <duncan.cross@...>
- Date: Wed, 2 Sep 2009 23:51:03 +0100
On Wed, Sep 2, 2009 at 11:06 PM, Andre de
Leiradella<aleirade@sct.microlink.com.br> wrote:
> (...) Or I'm completely missing an
> obvious way to require modules that are compiled into the application
> without hacks... In which case everyone is free to punch, ignore or
> enlighten me.
You should be able to make modules compiled into the application
available to "require" by adding them into the "package.preload" table
(the key is the module name as passed to require, and the value is the
luaopen_... function).
So, in your setup code for the Lua state, once the standard libraries
have been added in, something like this should be enough:
lua_getglobal(L, "package");
lua_getfield(L, -1, "preload");
lua_pushcfunction(luaopen_mymodule1);
lua_setfield(L, -2, "mymodule1");
lua_pushcfunction(luaopen_mymodule2);
lua_setfield(L, -2, "mymodule2");
// ...
lua_pop(L,2); // remove package & package.preload
-Duncan