Titan
Macro-Powered FFI for LuaJIT
About Me
Titan
Titan and Lua - Moons and Adaptation
What is an FFI? Why should I care?
Haxe Code
Foreign Function Interface
Compiled C/C++ Code
What are Problems with FFI?
LuaJIT FFI
Source : https://github.com/dyu/ffi-overhead
FFI Overhead (cumulative MS)
LuaJIT FFI Usage
LuaJIT FFI Idioms
LuaJIT maps common C value/accessor constructs to and from Lua idioms.
Some of these are necessarily awkward due to lack of direct Lua support (Pointer arithmetic, dereference)
LuaJIT FFI Conversions
C to Lua
Lua to C
LuaJIT FFI headaches
C Headers and C Macros
Parsing with Clang
Titan Workflow
Titan uses a compiler macro to define the header location*
*Folder support pending
Titan only supports the Lua target with the LuaJIT runtime
Titan Workflow
In the class file, all imported C method definitions are placed in the “Titan” namespace, and are accessible as static methods.
Structs are abstracts with constructors.
Titan Development Patterns
Titan loads all C FFI interfaces to a single namespace (Titan), since all C methods are loaded into a single namespace as well.
Organizing the FFI methods into modules, etc. is up to the developer. E.g. a cross-platform function for “sleep” might look like this =>
Don’t forget to include the compiled libraries when you distribute your code!
What can you do with Titan?
Titan works well with single-file libraries, such as:
Large multi-file libraries are possible, but painful for various platform specific reasons
nuklear
imgui
Recap
* Technically 4 namespaces : tags, types, labels, members of typed unions
When can I use Titan?
Titan is still not quite finished…
Some remaining issues:
The End!
Any questions?