Re: Phix: cffi.e
- Posted by Icy_Viking 1 week ago
- 418 views
andreasWagner said...
I looked at raylib for openeuphoria. Now I'm thinking about how and whether I can use this library with phix.
Can someone tell me how to use this code with phix with cffi.e for example:
In the functioncall Vector2 is not a pointer to a structure but the structure itself.
with ffi.e for openeuphoria this seems to work but i have no idea how to implement this with phix.
/* from raylib.h */ // Vector2, 2 components typedef struct Vector2 { float x; // Vector x component float y; // Vector y component } Vector2; RLAPI void DrawCircleV(Vector2 center, float radius, Color color);maybe i just haven't found it in the documentation yet.
Thank you
Andreas
Well I'm not sure how you'd wrap it in Phix, but I assume it'd be similar to how it is wrapped in OE.
include std/ffi.e --the FFI library --defines a struct we can use Vector2, we declare the x and y members as floats, as they are in the C library. public constant VECTOR2 = define_c_struct({ C_FLOAT, --x C_FLOAT }) --defines a struct of color, where members r,g,b,a are unsigned chars in the C library public constant COLOR = define_c_struct({ C_UCHAR, --r C_UCHAR, --g C_UCHAR, --b C_UCHAR --a }) public constant xDrawCircleV = define_c_proc(ray,"+DrawCircleV",{VECTOR2,C_FLOAT,COLOR}) public procedure DrawCircleV(sequence vector2,atom radius,sequence color) c_proc(xDrawCircleV,{vector2,radius,color}) end procedure --Then you can access the members like a sequence in an array DrawCircle({10,10},20,{255,255,255,255}) --Draws a circle at x: 10 and y: 10, radius: 20 and color values set 255,255,255,255
I hope that helps.