Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7776559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:55:00+00:00 2026-06-01T17:55:00+00:00

From my Ruby C Extension I wanted to create a new Geom::Vector3d instance from

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:55:01+00:00Added an answer on June 1, 2026 at 5:55 pm

    After communicating with the developers of Google SketchUp I have found the cause of this.

    SketchUp makes use of Data_Wrap_Struct to link their C classes with the Ruby classes. But they use an old method of allocating the data – which is within the #new method.

    In Ruby 1.8 you use rb_define_alloc_func() to do the allocation and you never mess around with #new. Ruby (1.6 and 1.8) defines #new to call rb_class_new_instance().

    Since I used rb_class_new_instance() on SketchUp’s old style classes the objects where not created properly, the allocation function was bypassed and never triggered. The error I got came from SketchUp, not Ruby.

    So the answer is, you can use rb_class_new_instance() to create new instances of classes provided they haven’t overloaded the #new method to do any initializations. Before Ruby 1.6 this was common for Ruby C classes if they needed to allocate data, but as of 1.8 it should be done with rb_define_alloc_func(). (Matz says so here: https://web.archive.org/web/20131003102349/http://www.justskins.com/forums/the-new-allocation-scheme-132572.html#post437362 )

    You can see the differences between Ruby 1.6 style and 1.8 style in this post: https://web.archive.org/web/20131003102349/http://www.justskins.com/forums/the-new-allocation-scheme-132572.html#post444948

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to ruby, how would I get the file extension from a url like:
I am new to Ruby, is there a way to yield values from Ruby
I'm kinda new to Flex. I have trying to send Hash from Ruby on
Is it possible to define an instance method in ruby from a string (the
I have implemented Ruby C extension(i.e. Invoking C function from ruby script) Following is
Im working on Ruby c extension, I have following code from c program, VALUE
I'm passing a date from Ruby to Javascript via JSON. It comes into Javascript
In this example from The Ruby Programming Language (p.270), I'm confused why the instance_eval
I came to ruby from PHP. How could i do the next thing in
I come from the ruby and python worlds where we have many libraries that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.