c struct map to ruby using SWIG

Posted by pierr on Stack Overflow See other posts from Stack Overflow or by pierr
Published on 2010-03-26T10:04:49Z Indexed on 2010/03/26 10:23 UTC
Read the original article Hit count: 220

Filed under:
|

Hi,

Is there any body can confirm the description here is true? My experience is that I can not use Example::Vector.new at all.

C/C++ structs are wrapped as Ruby classes, with accessor methods (i.e. "getters" and "setters") for all of the struct members. For example, this struct declaration:

struct Vector {
 double x, y;
};

gets wrapped as a Vector class, with Ruby instance methods x, x=, y and y=. These methods can be used to access structure data from Ruby as follows:

$ irb
irb(main):001:0> require 'Example'
true
irb(main):002:0> f = Example::Vector.new
#<Example::Vector:0x4020b268>
irb(main):003:0> f.x = 10
nil
irb(main):004:0> f.x
10.0

© Stack Overflow or respective owner

Related posts about ruby

Related posts about swig