[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Calling singleton from C

dachee1

11/7/2003 1:34:00 AM

While writing a C extension to Ruby, I'm trying to call a singleton
method that resides in another class but can't figure out what
parameters to give to rb_funcall() to do this. The problem boils down
to this:

class MyClass
def MyClass.my_func
...
end
end

and then in a Ruby extension, in C, I'm trying to call MyClass.my_func
using rb_funcall(), but I can't tell what the 'receiver' and 'id'
parameters should be:

rb_funcall(VALUE receiver, ID id, int argc, ...)

Note that I'm creating another Ruby class in my C extension, *not*
extending MyClass. I checked the FAQ but couldn't find anything
close, and couldn't quite figure it out from the "Programming Ruby"
book.

Thanks for any help,
Dwayne
1 Answer

ts

11/7/2003 9:52:00 AM

0

>>>>> "D" == Dwayne Achee <dachee1@yahoo.com> writes:

D> class MyClass
D> def MyClass.my_func
D> ...
D> end
D> end

D> and then in a Ruby extension, in C, I'm trying to call MyClass.my_func
D> using rb_funcall(), but I can't tell what the 'receiver' and 'id'
D> parameters should be:

D> rb_funcall(VALUE receiver, ID id, int argc, ...)

The receiver is MyClass, to retrieve it (if you don't have a reference)
just do

VALUE myclass = rb_const_get(rb_cObject, rb_intern("MyClass"));

then to call the method MyClass::my_func(12) just write

rb_funcall(myclass, rb_intern("my_func"), 1, INT2NUM(12));


--

Guy Decoux