Page 1 of 1

Automatic FFI binding generation from C headers

Posted: Tue Sep 22, 2020 6:27 pm
by gilzoide
I recently resurrected a project for automatically generating bindings from C to Lua: inclua (https://github.com/gilzoide/inclua).

It is currently able to generate LuaJIT FFI bindings directly from C header files using clang. Generated Lua code defines metatypes with automatically deduced __gc metamethod and other methods in the __index table, but supports adding extra definitions from a YAML or JSON file for metamethods or other fields to be placed in __index.

In the repository examples folder there are two examples with bindings for clang and raylib, and I also made a binding for CSFML. (These bindings are not useful for using with LÖVE, but the binding generator is, you get the idea)

Some things are missing, like generating entries for #defined constants and support for nested anonymous structs|unions, but I think it is quite usable right now. I plan on also supporting generation of pure C/C++ Lua bindings in the future. Haven't tested on Windows or OSX, but it should work just fine with a working installation of python 3 and clang.

I'm happy to help if anyone would like to try and am open for feedbacks and issue reports =D

Re: Automatic FFI binding generation from C headers

Posted: Thu Sep 24, 2020 11:02 pm
by RNavega
This looks tasty, thanks for sharing.