Subject: [ruby-ffi] Re: Layout for struct with array of struct values |
From: Simon Chiang |
Date: 1/4/10 7:35 AM |
To: ruby-ffi |
More digging revealed this is a bug in 0.5.0, closed in 0.6.0 (http:// github.com/ffi/ffi/issues/closed#issue/12). On Dec 30 2009, 12:17 pm, Simon Chiang <simon.a.chi...@gmail.com> wrote:
<simon.a.chi...@gmail.com> wrote:As an FYI, this raises a TypeError ('wrong argument type Class (expected Data)'): class Field < FFI::Struct layout :type, :ushort, :value, :pointer end class Multifield < FFI::Struct layout :theFields, [Field, 1] end On Dec 30, 10:37 am, Simon ChiangHow can I layout structures like this?
struct field { unsigned short type; void *value; };
struct multifield { struct field theFields[1]; };
If theFields was another type, say a pointer, then I'd try something like this (although I'm not sure if this would be correct either):
class Field < FFI::Struct layout :type, :ushort, :value, :pointer end class Multifield < FFI::Struct layout :theFields, [:pointer, 1] end
How can I specify 'struct field' as a type?