creating an object of a specific type

  • Thread starter Elias Athanasopoulos
  • Start date
E

Elias Athanasopoulos

Hello!

Consider I have:

static VALUE foo_init (self)
{
return self;
}

cFoo = rb_define_class ("Foo", cFoo);
rb_define_method (cFoo, "initialize", foo_init, 0);

Now I want, from a method of another class, to create a new Foo
object, which contains nothing.

I don't want to use Data_Make_Struct() since the object is
not connected with a C structure.

How can I do this simple thing? Perhaps using the NEWOBJ()
macro? But, again how can a specify that the new object's type
is Foo?

Regards,
 
E

Elias Athanasopoulos

What about:

VALUE fooInstance;
fooInstance = rb_funcall(cFoo, "new", 0, NULL);

Hope this helps,

It does. Thank you.

I wonder if it is complex enough to do the above purely in
C via the Ruby API (it would be faster, I guess).

Regards,
 
M

Michael Granger

What about:

VALUE fooInstance;
fooInstance = rb_funcall(cFoo, "new", 0, NULL);

Or:

#include <intern.h>
VALUE fooInstance = rb_class_new_instance( 0, NULL, cFoo );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top