From: Joe Van Dyk Date: 2005-12-13T13:57:07+09:00 Subject: Re: Accessing C structures in Ruby On 12/12/05, Eero Saynatkari wrote: > Joe Van Dyk wrote: > > (I've already looked at Swig, btw. I'd like to do this one by hand.) > > > > I have the following: > > > > typedef struct { > > double x; > > double y; > > double z; > > } VelocityRecord; > > > > typedef struct { > > double x; > > double y; > > double z; > > } PositionRecord; > > > > typedef struct { > > int id; > > int type; > > PositionRecord position; > > VelocityRecord velocity; > > } Player; > > > > Player Players[10]; > > > > > > The number of Players is fixed ahead of time. I want to be able to > > access that data from Ruby. Ideally, something like: > > > > module Simulation > > attr_accessor :players # Other stuff will be here > > class Player > > class VelocityRecord > > attr_accessor :x, :y :z > > end > > class PositionRecord > > attr_accessor :x, :y, :z > > end > > end > > end > > My typical recommendation is to just wrap a pointer to > the struct and pass that around. Then, for each method > just extract the pointer, access the correct field and > generate a VALUE out of that (inside the function that > corresponds to the method). Can you share more details? Is that essentially what I've done in my later posts on this?