In article <b89f690f5u / enews4.newsguy.com>,
Phil Tomson <ptkwt / shell1.aracnet.com> wrote:
>In article <007c01c30a90$9e798bc0$6401a8c0@MELONBALLER>,
>Chris Pine <nemo / hellotree.com> wrote:
>>----- Original Message ----- 
>>From: "Chris Pine" <nemo / hellotree.com>
>>
>>Maybe I'm not understanding, but can't you just call `new' on the class you
>>want to instantiate?
>>----------------------------
>>
>>Sorry if that was too short as to be unhelpful.  What I meant was that, if
>>you have the class object on the C side, you can just call `new' on it with
>>one of these:
>>
>>  rb_funcall
>>  rb_funcall2
>>  rb_funcall3
>>  rb_apply
>>
>>You will need to get the id for `new' first, with this:
>>
>>  new_id = rb_intern ("new");
>>
>>Most of this is on page 193 of the pickaxe.
>>
>>
>>Or, you could just do this (which is slower):
>>
>>  rb_eval_string ("YourRubyClass.new");
>>
>
>Hmmmm.... but how does the C side 'know' where my Ruby class is defined?  
>There doesn't seem to be a 'rb_require'.  I guess I should just try it 
>out.  I suppose if on the Ruby side I've got:
>
>  require 'SomeClass'
>  require 'MyCExtention'
>
>That perhaps MyCExtention might then have access to SomeClass (?)

OK, I tried it and that is how it seems to work.

It seems like to call the constructor of a Ruby class from C that you 
have to use rb_eval_string("YourRubyClass.new");  I don't see how you 
could do it otherwise since rb_funcall needs a receiver and you don't yet 
have a reciever:

  rb_funcall(VALUE recv, ID id, int argc, ...);

So how would you call Foo.new using rb_funcall?  You'd have to get the ID:
  rb_intern("Foo.new");
But then what would you use for recv?

At any rate, rb_eval_string is working fine for me.

Phil