You can do this in Luajit with the following trick:<p><pre><code> for f in *.lua; do
luajit -b $f `basename $f .lua`.o
done
ar rcus libmylib.a *.o
gcc -o myexe main-stub.c -I/usr/local/include/luajit-2.0 -L/usr/local/lib -lluajit-5.1 -Wl,--whole-archive libmylib.a -Wl,--no-whole-archive -Wl,-E
</code></pre>
Where main-stub.c looks like this:<p><pre><code> #include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <stdio.h>
int
main(void)
{
int status, result, i;
lua_State *L;
L = luaL_newstate();
luaL_openlibs(L);
/* load your lua entry point here */
status = luaL_loadfile(L, "mainluafile.lua");
if (status) {
fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));
exit(1);
}
result = lua_pcall(L, 0, LUA_MULTRET, 0);
if (result) {
fprintf(stderr, "Failed to run script: %s\n", lua_tostring(L, -1));
exit(1);
}
lua_close(L);
return 0;
}
</code></pre>
The executables produced are very small because you dynamically link to Luajit and statically link to your own Lua code. I have a full media scheduler running at 100 sites which is only 40k. And it runs like a demon on ARM too.
For multiple lua files, you can first bundle them into a single lua file using squish.[0]<p>[0]: <a href="https://github.com/LuaDist/squish" rel="nofollow">https://github.com/LuaDist/squish</a>
Also check:<p>Bundle [1], using LuaJIT<p>Luvi [2], which is also able to generate a single file executable and you can include static resources.<p>[1] <a href="https://luapower.com/bundle" rel="nofollow">https://luapower.com/bundle</a><p>[2] <a href="https://github.com/luvit/luvi" rel="nofollow">https://github.com/luvit/luvi</a>
Similar project for Python: <a href="http://www.pyinstaller.org/" rel="nofollow">http://www.pyinstaller.org/</a>
Works with multiple source files and supports widely used Python modules out of the box.
This is an interesting project, thanks for sharing.<p>Did you explore the possibility to use LuaJIT instead? The ability to do this and also integrate with Terra <a href="http://terralang.org/" rel="nofollow">http://terralang.org/</a> would create a great project!