Subject: Re: [ruby-ffi] 2D arrays |
From: Wayne Meissner |
Date: 12/10/09 9:30 PM |
To: ruby-ffi@googlegroups.com |
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 at http://github.com/ffi/ffi/issues so this will can get implemented at some stage. 2009/12/11 galdor <khaelin@gmail.com>:
/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 MartyanoffHi, 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