Mon February 24, 2014
$ cat hello.lua -- my little script print("hello from a lua script!") $ lua bundler.lua hello.lua | clang -xc -o hello - -lm -llua $ ./hello hello from a lua script!
The Lua Bundler is a little Lua script which generates a minimal C program that does nothing but execute another Lua script. I wish I had a better name for this (it reminds me too much of Ruby’s Bundler), but anyway, here are some of its cool features:
The Lua script is embedded into the resulting executable. So in the
above example, you can redistribute
hello but you don’t need to
You can pass arguments to the program, and they will be available in the Lua source inside the table called “arg”, just like when using the Lua interpreter the regular way.
The actual executable is
hello and not
lua, so your program will
show up in your process table as “hello”.
Your embedded script can call the Lua function
os.exit() and the given
status code will actually be propogated to the kernel.
The generated program is written to the standard output, so you can inspect it before compiling it.
The generated C program should store Lua bytecode, not Lua source.
Support for multi-file projects… although this is probably as easy as concatentating all of the component sources.