Subject:
Re: [ruby-ffi] Re: struct questions
From:
Wayne Meissner
Date:
12/19/09 10:34 PM
To:
ruby-ffi@googlegroups.com

2009/12/20 rogerdpack <rogerpack2005@gmail.com>:
> When I first started using FFI::Struct's
>
> I anticipated being able to call methods, like
> a = Struct.new
> a.name = "hello there"
>
> (since that's how you access them in C, and they are certainly not
> hashes).  Would a patch for such be acceptable?

I considered this at one point, but it leads to name clashes with
other methods you might want to call on a Struct instance - so you
have a namespace issue.

e.g.

class S < FFI::Struct
  layout :size, :int
end

s = S.new

What does s.size return?  The size of the struct, or the contents of
the native field called size?

Using the [] method to access struct fields neatly avoids it.

If you really want it, ffi-swig-generator generates accessor methods
like that for every field, but it should not be a part of ffi itself.