lua-users home
lua-l archive

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

I'll describe how I'm building my Lua application.  Hopefully someone can
tell me either a better way, or it might expose a need in the language that
the Lua designers might want to consider.

Let's say I have four Lua files named a.lua, b.lua, c.lua, and d.lua.
Here's the form:

     {some code}

     {some code}

     {some code}

     {some code}

(The file a.lua is my top-level file.)

This works great interactively.  I can type "lua a.lua" and it will
correctly decend down the tree of subordinate files, compiling as it goes.
But this doesn't work if I want to create a single precompiled image from
these Lua files.  The dofile() function is executed at run-time not
compile-time, so simply typing "luac a.lua" only compiles the top-level

What's necessary here is to give luac the complete list of Lua files needed
by the application.  But I can't just type "luac *.lua" because the order
of Lua files is important-- there are various initializations done and they
must be done in the proper order.  I need to compile all the subordinate
files first, which means the preceeding example needs this command line:

     luac d.lua b.lua c.lua a.lua

What I did was write a short script that builds a dependency list of all
files, and then executes luac with the files in the correct order, like in
the previous command line example.  That works fine, but there is one last
piece here:  I have to temporarily take over the dofile function:

     orginalDofile = dofile
     dofile = function () end

And then I restore it when the "main" code runs.  This prevents the dofile
() in the Lua files from actually running.

This all works just fine, but it seems overly complex and convoluted.  So
assuming this description of what I'm doing is clear, does anyone have any
better ideas?  I guess a more generic question is how are people managing
large Lua projects that cover many files?