You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#ifndef MYLIB_H
#define MYLIB_H
#include <stdint.h>
int64_t mylib_add(int64_t a, int64_t b);
int64_t mylib_mul(int64_t a, int64_t b);
#endif // MYLIB_H
mylib.c
#include <stdint.h>
#include "mylib.h"
int64_t mylib_add(int64_t a, int64_t b) { return a + b; }
int64_t mylib_mul(int64_t a, int64_t b) { return a * b; }
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 the UmkaStackSlot* args, where the last argument is at index 0, next argument is at index 1, etc and writes its results (if any) to UmkaStackSlot* ret. After writing the wrapper function we need to write a declaration for it in Umka fn um_mymod_add(a, b: int) : int; and also the function that users are going to call that just calls it fn add*(a, b: int) : int { return um_mymod_add(a, b); }. And finally we have to register the function umkaAddFunc(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.
The text was updated successfully, but these errors were encountered:
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.The text was updated successfully, but these errors were encountered: