title: How does one get the instance of a Ruby class running in the current RB file? (Embedding Ruby in C++)
body: <p>I have embedded Ruby inside my C++ application. I have generated the bindings using SWIG.</p>
  
  <p>Basically, I run the ruby file and then Ruby takes over and calls my C++ class.</p>
  
  <p>Based on my previous question, I would like to get the current instance of the class that is defined in the ruby file back to the C++ class so that I may execute instance methods.</p>
  
  <p>I execute the ruby file as follows:</p>
  
  <pre><code>rb_eval_string_protect(&lt;ruby script string&gt;, &amp;status );
  
  rb_funcall(Qnil, rb_intern("main"), 0);
  </code></pre>
  
  <p>The global main method in the script creates an instance of the defined class in the file. That's the instance I am after.</p>
  
  <p>If I have to, I will add a parameter or another function to pass the instance back, however, I'm not sure how to define that in C++ so that when SWIG generates the binding, it all works ok.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Previous Question: <a href="https://stackoverflow.com/questions/496304/calling-ruby-class-methods-from-c" title="Calling Ruby class methods from C++">Calling Ruby class methods from C++</a></p>