Subject: [ruby-ffi] Re: Functions returning structures |
From: galdor |
Date: 12/14/09 3:42 PM |
To: ruby-ffi |
Thank you, it just works! I also had to use .by_value for parameters, of course. I'll notify the author of ffi-swig-generator about this, its tool doesn't produce these annotations. Regards, Nicolas Martyanoff On Dec 14, 10:33 pm, Wayne Meissner <wmeiss...@gmail.com> wrote:
You need to specify the return type as ALLEGRO_COLOR.by_value (same for any struct-by-value parameters). 2009/12/15 galdor <khae...@gmail.com>:Hi,Let's define a C function which returns a plain structure:typedef struct { int r, g, b, a; } ALLEGRO_COLOR;ALLEGRO_COLOR al_map_rgb(unsigned char r, unsigned char g, unsigned char b);Now we bind it:class ALLEGRO_COLOR < FFI::Struct layout :r, :float, :g, :float, :b, :float, :a, :float endattach_function :al_map_rgb, [:uchar, :uchar, :uchar], ALLEGRO_COLORBut the following ruby code doesn't work:bgcolor = al_map_rgb(20, 20, 20) fgcolor = al_map_rgb(20, 40, 80) al_clear_to_color(bgcolor)The screen is cleared with rgb(20, 40, 80), instead of rgb(20, 20, 20). I don't know how stack allocation is performed, I must be doing something wrong.How should I work with stack-allocated structures ?Regards,Nicolas Martyanoff