complete rewrite for simpler architecture
This commit is contained in:
22
Readme.md
22
Readme.md
@@ -1,23 +1,15 @@
|
||||
# MKLua
|
||||
|
||||
A small tool for compiling a C + Lua project to an executable
|
||||
A small tool for generating a C file that bundles a lua library. This can either be used to bundle a lua library as a single .so file, or bundle a lua application into an executable. NOTE: sine lua uses .so files for native code, unfortunately, it would be prohibitively complex to rebuild all .so modules into static libraries. For this express purpose, self-contained executables are not yet possible.
|
||||
|
||||
# **BIG RED LETTERS ALERT!!!**
|
||||
## Output C file
|
||||
|
||||
NOT PRODUCTION READY!!!!! USE AT YOUR OWN RISK!!!!!!!!! WORKS ON LINUX ONLY!!!!!
|
||||
This tool will output a single C file, which contains `luaopen_xxx` functions for each entry you specify. If those entries depend on anything, they will be included in the executable, but not exposed. Aditionally, if `--main` is specified, a boilerplate `int main` function will be generated, which will call the export of the first entry.
|
||||
|
||||
## How does it work?
|
||||
## Output makefile
|
||||
|
||||
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`.
|
||||
In this mode (`--makefile`), the tool will output a boilerplate makefile, which will use mklua to emit a C file, and then will compile it to a binary. This Makefile works out of the box (you only need to specify the output filename). However, feel free to modify the file.
|
||||
|
||||
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).
|
||||
## Output dependencies and libraries
|
||||
|
||||
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.
|
||||
This tool can also be used to output all the files that the entries depend on. This is useful for makefile scripts, in order to detect changes. `--deps` prints all the files and `--libs` prints only the files found from `cpath`
|
||||
Reference in New Issue
Block a user