Subject:
[ruby-ffi] Re: 2D arrays
From:
galdor
Date:
12/11/09 1:42 PM
To:
ruby-ffi

Thank you for your answer>
I filled an issue here on http://github.com/ffi/ffi/issues/#issue/18.

Regards,

Nicolas Martyanoff

On Dec 11, 4:30 am, Wayne Meissner <wmeiss...@gmail.com> wrote:
> There is currently no way to declare 2D arrays.
>
> One work around for a small struct like that is to declare 4 arrays.
> e.g.
>
> class ALLEGRO_TRANSFORM < FFI::Struct
>    layout :m0, [:float, 4], :m1, [:float, 4], :m2, [:float, 4], :m3, [:float, 4]
> end
>
> Then instead of accessing the second element of the first array as
> [:m][0][1], it would be [:m0][1]
>
> Kinda messy, but its what you will have to do for now.
>
> Please file an issue athttp://github.com/ffi/ffi/issuesso this will
> can get implemented at some stage.
>
> 2009/12/11 galdor <khae...@gmail.com>:
>
> > Hi,
>
> > I'm trying to bind the following structure:
>
> > struct ALLEGRO_TRANSFORM {
> >   float m[4][4];
> > };
>
> > But with the following FFI declaration:
>
> > class ALLEGRO_TRANSFORM < FFI::Struct
> >    layout :m, [[:float, 4], 4]
> > end
>
> > I get the following error:
>
> > /usr/lib/ruby/gems/1.9.1/gems/ffi-0.6.0pre/lib/ffi/struct.rb:177:in
> > `add_array': undefined method `alignment' for [:float, 4]:Array
> > (NoMethodError)
> >        from /usr/lib/ruby/gems/1.9.1/gems/ffi-0.6.0pre/lib/ffi/
> > struct.rb:177:in `array_layout'
> >        from /usr/lib/ruby/gems/1.9.1/gems/ffi-0.6.0pre/lib/ffi/
> > struct.rb:106:in `layout'
> >        from lib/allegro/ffi_allegro.rb:558:in
> > `<class:ALLEGRO_TRANSFORM>'
> >        from lib/allegro/ffi_allegro.rb:557:in `<module:Allegro>'
> >        from lib/allegro/ffi_allegro.rb:4:in `<main>'
>
> > Is there a specific syntax for 2D arrays ?
>
> > Regards,
>
> > Nicolas Martyanoff
>
>