Re: Phix: cffi.e
- Posted by petelomax 6 days ago
- 332 views
In Phix I'd start with something like this (NB completely untested)
include cffi.e constant t_Vector2 = """ typedef struct Vector2 { float x; // Vector x component float y; // Vector y component } Vector2; """ constant idVector2 = define_struct(t_Vector2), pVector2 = allocate_struct(idVector2) -- (you might get away with passing/need to pass #RRGGBBAA values directly, -- and/or allocate(4) and poke4(said) might be much neater...) constant t_Color = """ typedef struct Color { unsigned char r; // Color red value unsigned char g; // Color green value unsigned char b; // Color blue value unsigned char a; // Color alpha value } Color;""" constant idColor = define_struct(t_Color), pColor = allocate_struct(idColor) -- I can tell you this kind of thing simply won't work: --constant xDrawCircleV = define_c_proc(ray,"+DrawCircleV",{VECTOR2,C_FLOAT,COLOR}) -- instead: local constant xDrawCircleV = define_c_proc(ray,"+DrawCircleV",{C_PTR,C_FLOAT,C_PTR}) global procedure DrawCircleV(sequence vector2, atom radius, sequence color) atom {x,y} = vector2 set_struct_field(idVector2,pVector2,"x",x) set_struct_field(idVector2,pVector2,"y",y) integer {r,g,b,a} = color set_struct_field(idColor,pColor,"r",r) set_struct_field(idColor,pColor,"g",g) set_struct_field(idColor,pColor,"b",b) set_struct_field(idColor,pColor,"a",a) c_proc(xDrawCircleV,{pVector2,radius,pColor}) end procedure -- if an alpha of 255 means fully transparent, this won't show anything: DrawCircleV({10,10},20,{255,255,255,255})