lua-users home
lua-l archive

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


2009/4/12 Wolfgang Pupp <wolfgang_pupp@yahoo.de>:
> I'm currently trying to merge interpreter (LuaJIT) and some modules (lpeg, lfs, md5) into one library (a windows DLL, using MinGW).
>
> My (quite naive) approach is to compile the C- based part of the modules into object files and to link them with the interpreter's object files.
> I intended to just wrap the Lua- code in some luaL_dostring- commands (is there any better way? I once ran across a LuaToC- converter, but that one only worked for Lua 4.x).
>
> The problem arises with the loading of the modules- I assume that it would be best to set the corresponding entries of the package.preload- table, because that way, 'require' would still work as expected.
> But where to change the preload- table? I suppose that I have to edit one of the interpreters source- files, but which one? Is there any designated function stub/... for changing the preload- table?
>
> If there is a better way to do this, or if there exists already some script/tool/etc. which does something like that (merge interpreter and modules, or convert Lua- to C- code) please point me at it!

I assume the clients of your DLL are calling lua_newstate. It's the
code that creates the initial lua_State that's supposed to populate
the package.preload table, ie. your clients. You can eventually add
your libraries in linit.c so that clients calling luaL_openlibs have
your libraries loaded. The only solution to force your libraries to be
loaded with every new interpreter is to change the lua_newstate
function.

If your DLL has some higher-level function that create a Lua state
(like DllMain, or some plugin API entry point), you can populate
package.preload there.