|
On Jul 31, 2008, at 1:42 PM, Jerome Vuarand wrote:
You can try the following script to generate a bytecode file of all the listed modules (see the beginning of the script). Then in your final program, just call dofile("preload.lbc") before using (through 'require' as usual) any of your modules.
Thanks for this idea. Wouldn't it make sense to implement this in luac as an option? Today, luac compiles multiple modules by prepending code that calls each chunk (i.e. module). As a consequence, embedded 'requires' are executed before all modules are executed. Is this behavior still useful in the presence of 'module' and 'require'? I think it would be better to defer these calls using the construction you suggested: for each module, call a hook that either executes the module (same behavior as now) but also could be used to add the module to package.preload. In the latter case execution would be triggered by 'require', which would be after all modules are entered.
In general, I find compiling all Lua code into a single bytecode file very attractive for deployment. On a desktop system the bytecode file would be loaded by lua(1), in an embedded system the bytecode could be embedded as a string into a C application.
-- Christian