WIP single-file and pure Lua bindings for Flecs using the LuaJIT FFI. The aim is to implement at least all the basic Flecs' features that allow making a game. Unsafer operations are not implemented yet. Based on https://github.com/flecs-hub/flecs-lua/
- Do a standard CMake build. This will automagically run
utils/preprocess.(sh|bat)having the project root as the current working directory every time the Lua source or the Flecs header change. The script generates the FFI cdefs for Flecs fromlibs/flecs/flecs.h, appendssrc/ecs.luaand generates the final Lua file, ready to use, indistr/ecs.lua. In Windows, you need to havecl.exeavailable in yourPATH. One way to do it is by executing it in a "Command Prompt for VS 20xx," available from the start menu. The output is equivalent to LuaJIT, but it is uglier. I wouldn't use it to generate the distribution Lua file that is to be committed. - Download, compile and install LuaJIT following the directions in the official webpage, or just
install it from your distro's package repositories, but I don't personally use those. For Windows, after compiling
LuaJIT, copy or symlink
lua51.libfound atluajit/srcafter the build to a new directory under this project's rootlibs/luajit. Copylua.h,luaconf.h,lualib.handlauxlib.hto a new directorylibs/lua/luajit-2.1. Blame W*ndows for not having a standard way to install development libraries. - When running the test program, make sure the
distr/ecs.luaandsrc/tests.luafiles are available in the current working directory. CMake takes care of this automatically (copies the files to the binary directory).
On the Lua side, you only need distr/ecs.lua, the standard Lua libraries, and the FFI, BitOp and string buffer
LuaJIT libraries, all included with the latest LuaJIT commits. On the C side, your app needs to export Flecs' symbols,
which *nix compilers do by default. For Windows, you need to comment out the second line #define flecs_STATIC in
flecs.h and define flecs_EXPORTS, probably unless you use Flecs as a DLL, but I haven't tested this. Also, it's
important to define FLECS_SOFT_ASSERT to make Flecs do some checks and allow for recoverable errors, specially if you
run third-party code, like game mods! Finally, just run ecs.lua however you want. It returns the entire module as a
table.
When running utils/preprocess.sh, any arguments you pass will be forwarded to cc. Therefore, you are able to
customize Flecs' macros. Notably, you can customize ecs_float_t and ecs_ftime_t to use double precision, for
example with ./utils/preprocess.sh -Decs_ftime_t=double -Decs_float_t=double. You MUST make sure to preprocess and
compile flecs.c with the same definitions, otherwise chaos will ensure!
This library uses ffi.C.free() to release the memory allocated and returned by Flecs, so don't pass custom memory
management functions to Flecs (for example, by using ecs_os_set_api())! This unsafe operation is not yet implemented.
- Ensure the library is more or less safe to expose to third-party code, like mods.
- Allow for custom
ecs_os_api_t.