It is quite straightforward to make your own version of the commandline interpreter, then you just create the Lua state and use C API commands to push the libraries into the preload table. You could have a look at my Grunt source code (www.luaforge.net/projects/grunt) - I do it with C++ but it could be easily adapted to C. -----Original Message----- From: lua-bounces@bazar2.conectiva.com.br [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Jerome Vuarand Sent: 23 April 2009 14:33 To: Lua list Subject: Re: Packing Lua-interpreter and modules into one library 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.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature