lua-users home
lua-l archive

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


On Mon, Oct 04, 2004 at 11:57:18AM +0100, Daire Stockdale wrote:
> Hello
> 
> I would like to be able to compile several Lua scripts that refer to each
> other via the 'require' method into a single pre-compiled byte-code file (or
> chunk). Compiling any one file using the supplied Lua compiler does not
> compile other files that are 'required'. I would like a method that allowed
> me to compile a Lua 'application', a set of lua files, into a single Lua
> chunk. My run time environment will not have the capability to interact with
> files, but I do not want to have to write the application as a single Lua
> file. Does anyone have any suggestions how to do this?

It's easy using Unix tools. If you're on Windows, you can use Cygwin.
The stuff below is untested, and makes a couple of assumptions that
might not be valid for you, but it shouldn't be hard to tweak.

- Get a list of dependencies:

grep require *.lua | sed 's/\(.*\):.*require "\(.*\)"/\1 \2.lua/' > deps

- Get a total ordering:

tsort deps | tac > order

- Make require do nothing:

echo "function require() end" > dummy_require

- And put it all together:

cat order | xargs cat dummy_require > everything.lua

-- Jamie Webb