2 ms·
I'm tackling this issue from two sides: (1) Change the C-API to make it more "binding-generator-friendly", for instance by adding a range/slice-struct to th C-
by flohofwoe 6y ago
I'm tackling this issue from two sides:
(1) Change the C-API to make it more "binding-generator-friendly", for instance by adding a range/slice-struct to th C-API which bundles a pointer and associated size, or specially named typedefs that only exist to give the binding generator hints for special case handling. By adding a C-type which represents a range/slice, it's easier to connect high level languages to the C API, and as a nice side effect, the C-API also becomes safer and more "correct", because pointers and associated sizes can be passed around as one item.
(2) Make the bindings-generator configurable on a per-language and per-API basis, this can be as simple as a map which overrides type- and function-names, or injects manually written code into the generated bindings.
The goal is to make the generated bindings more idiomatic to the target language.
This mostly works if you have control over the underlying C-API of course, e.g. the language bindings are created by the original C-library project, not as an external project to convert a fixed C-API.
I wrote a blog post about this whole topic:
https://floooh.github.io/2020/08/23/sokol-bindgen.html https://floooh.github.io/2020/08/23/sokol-bindgen.html
...and here's an example of such semi-auto-generated Zig bindings:
https://github.com/floooh/sokol-zig/tree/master/src/sokol https://github.com/floooh/sokol-zig/tree/master/src/sokol
...for instance note the "injected" helper functions here:
https://github.com/floooh/sokol-zig/blob/1c93f60ad178869b84df63f6b5ecce9fdb5a049e/src/sokol/debugtext.zig#L5-L45 https://github.com/floooh/sokol-zig/blob/1c93f60ad178869b84d...