Yes.
luajit -b Module.lua Module_bc.c
will compile a module to bytecode and output a C array initializer containing that bytecode.
If you build with shared libraries enabled and export this array from the main executable, require
will find it (and will not need to look for Module.lua
.)
To test that it is working, set package.path = ""
before require
ing the module. If it still works, you know the preload is working and it is not just using the Module.lua
file from the current directory.
http://luajit.org/running.html
Other things to keep in mind:
- If the module depends on an external file (using
io.open
), that file still needs to be present. For example some ffi modules try to open a C header file, to pass toffi.cdef
- You need to keep
Module_bc.c
in sync withModule.lua
, e.g. with a Makefile recipe, or you will see some confusing bugs!