Subject:
[ruby-ffi] Re: Layout for struct with array of struct values
From:
Simon Chiang
Date:
12/30/09 1:17 PM
To:
ruby-ffi

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 Chiang <simon.a.chi...@gmail.com> wrote:
> How 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?