lua-users home
lua-l archive

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

On Wed, Sep 2, 2009 at 11:06 PM, Andre de
Leiradella<> 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_setfield(L, -2, "mymodule1");
lua_setfield(L, -2, "mymodule2");
// ...
lua_pop(L,2); // remove package & package.preload