lua-users home
lua-l archive

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


Hi all,

I'm introducing Squish, a quick tool I put together over the weekend
to package some libraries and applications (Prosody, etc.) I'm working
on: http://matthewwild.co.uk/projects/squish

Squish was inspired by lhf's luac.lua which can pack multiple scripts
and modules together into a single compiled chunk. Squish is designed
to solve exactly the same problem. The only difference is that Squish
by default works only on source code.

So here are some nice features of Squish...

...generates plain Lua source code, and uses package.preload to inject
the packed modules into the script at runtime.
...contains several filters which can be run on the generated output
to compress it to as small a size as possible
...can be made to preserve filenames and line numbers in the generated
code, so Lua tracebacks and errors are not useless
...takes instructions from per-project "squishy" files, which are
essentially Lua scripts with the ability to control the squishing
process
...supports 'resources', or packing standard (non-code) files into the
script. Even supports using io.open() to access these in-memory.
...is written in pure Lua, and has no hard binary dependencies.

Ideas for the future...

In addition to the existing compression methods, it would be great to
add a 'gzip' method, whereby the script is compressed during squshing
and decompressed at runtime. The only reason I did not make such a
filter is that there appears to be no gzip /compression/ algorithm in
pure Lua. I wanted squish to remain free of external dependencies, but
if someone adds this filter then I would be happy to include it
whether it uses an external gzip library or not (as long as the
decompression code can be written in Lua).

Just for fun, it would be interesting to have a lua2c output filter,
using http://github.com/davidm/lua2c/tree/master :)

Support for packing binary modules is planned. This would make the
result non-portable (or would it, if we packed both a statically
linked .dll and .so?) but would work for per-platform distribution.
The main reason there is no binary module support right now is that
they need extracting to a file before they can be used, and I couldn't
decide on the best location to extract to (current directory?
os.tmpnam?).

Other ideas are welcome. I had fun building Squish, and I hope others
will have fun hacking on it too.

Thanks...

Squish draws on a lot of code and ideas from lots of different people
and places. Apologies if I miss anyone, but:
The minify filter is based on code from LuaSrcDiet, which is based on
code from Yueliang. The compile filter uses minichunkspy which was
written by sanooj in IRC in a few hours last night, after I complained
about the complexity of parsing bytecode in pure Lua. The debug filter
also uses minichunkspy to strip debug information from the compiled
code. The uglify compressor uses llex.lua, also from
LuaSrcDiet/Yueliang, and the idea came from lhf and rjek in IRC.

Happy squishing :)
Matthew