Translate all of the Lua source code files to object files and put them in a static library:
for f in *.lua; do
luajit -b $f `basename $f .lua`.o
done
ar rcus libmyluafiles.a *.o
Then link the libmyluafiles.a
library into your main program using -Wl,--whole-archive -lmyluafiles -Wl,--no-whole-archive -Wl,-E
.
This line forces the linker to include all object files from the archive and to export all symbols.
For example, a file named foo.lua can now be loaded with local foo = require("foo")
from within your application.
Details about the -b
option can be found on Running LuaJIT.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…