Subject:
Re: [ruby-ffi] Pointer to a struct - how to cast?
From:
Chuck Remes
Date:
5/21/10 8:12 AM
To:
ruby-ffi@googlegroups.com

On May 21, 2010, at 8:10 AM, DA wrote:

> On Thu, May 20, 2010 at 9:13 PM, Wayne Meissner <wmeissner@gmail.com> wrote:
>> Try using FFI::Pointer#+
>> 
>> e.g.
>> 0.upto(tis[:len]).each do |i|
>>  s = FM::FTexFtItemT.new(tis[:val] + (i * FM::FTexFtItemT.size))
>>  # do stuff with s here
>> end
> 
> Hi Wayne, thanks a bunch, this works perfectly (minus the .each).
> 
> Would this be a good example to add to the wiki, perhaps under
> "Structs > Array of Structs"?  I would be happy to add it.  (It also
> would illustrate using a union in a struct).

Drew, please add it to the wiki. I used a similar technique to solve the same problem but your example is better since it uses unions too.

cr