lua-users home
lua-l archive

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


On Sun, 12 Apr 2009 08:56:35 +0000 (GMT)
Wolfgang Pupp <wolfgang_pupp@yahoo.de> wrote:

> 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!

There is a way, and I am in the process of writing such a tool. I have
created a GUI that runs a Lua program, samples the required packages,
and allows to compile the Lua program and all required packages into a
single blob of bytecode. This work is based on a modified version of
the luac.lua compiler by Luiz Henrique de Figueiredo:
http://lua-users.org/lists/lua-l/2008-08/msg00092.html

I will probably add a "save as C code" option for the compiled bytecode
as well. One would end up linking that compiled blob, liblua, and the
custom C modules together, register the C libraries during Lua's module
open procedure and run the bytecode. 

What I am doing here is that I run the program and look into the
package.loaded table afterwards, and then try to determine the file
names of these packages using the package.path and package.config
fields. (Note that I am using a patched version of luac.lua that
respects the complete package paths - this is crucial for my
requirements.)

But it's still some work, and the compiler will be tied to the tekUI
package. I was not planning to do a command-line version. A screenshot
can be seen here: http://tekui.teklib.org/images/compiler.png

- Timm

-- 
Timm S. Mueller <tmueller@schulze-mueller.de>
Schulze & Mueller GbR, Erbacher Straße 26, 64342 Seeheim-Jugenheim,
Gesellschafter: Franciska Schulze, Timm S. Mueller,
Tel. +49 6257 648853-0, http://www.schulze-mueller.de/