From my Ruby C Extension I wanted to create a new Geom::Vector3d
instance from the Google SketchUp Ruby API: https://developers.google.com/sketchup/docs/ourdoc/vector3d
My initial code was this:
static inline VALUE
vector_to_sketchup( Point3d vector )
{
VALUE skp_vector, args[3];
args[0] = rb_float_new( vector.x );
args[1] = rb_float_new( vector.y );
args[2] = rb_float_new( vector.z );
skp_vector = rb_class_new_instance( 3, args, cVector3d );
}
This however raised an error:
Error: #<ArgumentError: wrong type - expected Sketchup::Vector3d>
Instead I had to call the ruby new
method - like so:
static inline VALUE
vector_to_sketchup( Point3d vector )
{
VALUE skp_vector;
skp_vector = rb_funcall( cVector3d, sNew, 3,
rb_float_new( vector.x ),
rb_float_new( vector.y ),
rb_float_new( vector.z )
);
return skp_vector;
}
I ran into the same problem with Geom::Point3d and Sketchup::Color.
rb_class_new_instance
is the preferred way to create a new instance in Ruby C, right?
Anyone got any idea why I needed to call new
? Some oddity with how the class was defined in SketchUp?