1.6 KiB
MKLua
A small tool for compiling a C + Lua project to an executable
BIG RED LETTERS ALERT!!!
NOT PRODUCTION READY!!!!! USE AT YOUR OWN RISK!!!!!!!!! WORKS ON LINUX ONLY!!!!!
How does it work?
This tool assumes you're working on an executable, that may have lua and C files. Each file will correspond to a single module, that can be used using lua's require
.
You will specify where these files are located, using the --lua-dir
and --c-dir
options, for lua and C files respectively. All files in those folders will be included in the final build, and the module names used will be relative to the folders, with the lua require rules respected (.../init.lua
or .../init.c
will be the default import of the folder, slashes become dots).
C files will be required by calling the lua_CFunc
function, by the name of lualib_open_[name]
, where name
is the name of the module, with the dots replaced with underscores. This function is expected to return exactly one value, the exported value by the C module.
Finally, a module name must be specified as the entry of the executable. This module should export a function, which will act as the main function of the program.
How does it really work tho?
The lua files will be compiled by lua's string.dump
function, with the debug information stripped by default. Then, each bytecode sequence will get loaded into package.preload
, which is an internal table of lua's require
mechanism.
C files on the other hand will get linked together and the lualib_open_...
function will get called inside the auto-generated int main
function.