Open luauser32167 opened 7 months ago
I think @robloach may already have something like this. He was working on Umka bindings for raylib:
Thanks. Was a fun project to put together. Umka's binding API made it really easy to integrate with raylib. While I could've likely used Umka to parse raylib.h and output the Umka/C bindings, I am lazy and used JavaScript to build the generator.
I'd be more than happy with moving the generator to be a bit more abstract, or ported to Umka itself. Feel free to make some issues in the queue if you have any ideas.
Suppose we have the following C library:
mylib.h
mylib.c
and we wanted to use it from Umka:
script.um
We would need to write the following "glue" code:
Having to manually write this "glue code" is annoying because for every function that we want to make available to
script.um
, we need to make changes to 3 places. The first and most tedious is the wrapper function that reads its arguments from theUmkaStackSlot* args
, where the last argument is at index 0, next argument is at index 1, etc and writes its results (if any) toUmkaStackSlot* ret
. After writing the wrapper function we need to write a declaration for it in Umkafn um_mymod_add(a, b: int) : int;
and also the function that users are going to call that just calls itfn add*(a, b: int) : int { return um_mymod_add(a, b); }
. And finally we have to register the functionumkaAddFunc(U, "um_mymod_add", &um_mymod_add);
.My proposal is that there should be a tool that generates the "glue code" from header files (
mylib.h
). It doesn't have to be super robust to be useful, it could just handle a subset of C declarations (struct, enum and function declarations) that can be mapped to Umka.