How does one get the instance of a Ruby class running in the current RB file? (Embedding Ruby in C++) -
I've embedded Ruby inside my C ++ application I have created bindings using SWIG.
Actually, I run the Ruby file and then moves to Ruby and calls my C ++ class.
Based on my previous question, I get the current example of the cloud which is defined in the Ruby file back in the C ++ class so that I can execute the instance methods.
I execute the Ruby file as follows:
rb_eval_string_protect (& lt; ruby script string & gt;, & amp; status); Rb_funcall (Qnil, rb_intern ("main"), 0);
The global main method in the script creates an example of the class defined in the file. This is the example that I am after that.
If I have to do, then I will add a parameter or some other function to return the example, however, I'm not sure how to define it in C ++ so that SWIG
Previous question:
rb_funcall ()
is applied So the trick is to actually think about how you will get the value of the value of that receipt? If it is the main return value only, such as
# I'm a Ruby script! Main_retval = main ()
Then returning the return value in C is the same:
// I have some C (or C ++) code of VALUE main_retval; // ... rb_eval_string_protect ("...", and position); Main_retval = rb_funcall (knil, rb_interm ("main"), 0); < / Code>
and you issue The rabbi will return the context by returning the validity
.
You can use this object as normal, calling methods and like
VALUE main_text_ass_string = rb_funcall (main_shadow, rb_index ("to_s"), 0);
Comments
Post a Comment