I am trying to call a class method from C ++ I have tried to RB_Internet all the tasks, I could think that this work, but I have not earned anything.
Example class
class calltest def (trying to do something here) end
trying to call C ++:
Rb_funcall (?, rb_intern ("go"), 0);
What's going on? Space? I know that I use that there, I call the global work, but I like class methods.
Am I going in the wrong direction?
In addition to this, I would like to, if possible, do not need to know the name of the class before time, but if I need it that I know what it is, then I will give it my application I can try to go through the name of
I am using SWIG to generate binding.
First of all, go
we defined it, not class system, Rather a example method .
As an object-oriented language, all Ruby methods require a receiver, which is an object that is applicable to. For example methods, the receiver is an example of class for class methods, the receiver is class object.
The? Placeholder You have the slot for the receiver of the method call.
If you want to leave it as an instance method, then you need to do this:
rb_funcall (A_CallTest_instance, rb_intern ("go"), 0 );
Where a_CallTest_instance
you rb_class_new_instance ()
. An example of CallTest created using
was that if you create it in a class method:
class callstaff df self.go # ... and end < / Code>
then classify you as CallTest
as your receiver:
rb_funcall (class, rb_inter ("go"), 0);
You can use the reference rb_const_get ()
for the calltest
class> VALUE klass = Rb_const_get (rb_cObject, rb_intern ('calltest')); Use rb_cObject
because the CallTest
is defined in the global context. I suggest reading Expanding Ruby about the chapter in Picayx.
Comments
Post a Comment