Subject:
[ruby-ffi] struct questions
From:
rogerdpack
Date:
12/18/09 7:00 PM
To:
ruby-ffi

A few random questions for members of the group...

I've noticed that inheritance doesn't seem to work...

  class SimpleStruct < FFI::Struct
    layout  :value, :double,
            :name, :string
  end

 class S2 < SimpleStruct; end
 puts S2.members # fails NoMethodError: undefined method `members' for
nil:NilClass

Is there any means for inheritance? Is this a bug?  (as another side-
effect, the parent marshal's correctly but the child doesn't--is that
a bug?).

With char arrays, it seems "difficult" to insert a string

(rdb:1) ss[:title] = "abc"
ArgumentError Exception: put not supported for
FFI::StructLayout::Array

is there an easier way than ss[:title][0] = 33; ss[:title][1] = 34; //
one at a time?

If the only reason "put" is not supported is because it is on the todo
list, I could help with that.

I would also be happy to hack up a patch that made Struct#inspect more
visually friendly

i.e.
#<SnarlStruct:0x13221c0>
becomes
#<SnarlStruct field1: value1, field2: value2...>

if there's any interest.

Thoughts?

In good news, I was able to successfully convert ruby/dl of the Snarl
gem into ffi and it works [now ffi compatible--yea].

Thanks!
-r