From: Tobias Grimm Date: 2004-08-17T17:14:59+09:00 Subject: Re: Embedding Ruby as plugin Joel VanderWerf wrote: > Not sure I understand. Where is the ruby interpreter in this picture? > Your C++ app embeds it? Or plugin.so embeds it? plugin.so embeds it. I can't change the C++ app, it will never know, that one of it's plugins uses ruby. > What if you just set a global variable, $interface, before loading > rubyscript.rb, which references this global? > > Is the problem then that you don't want to use a global, for the usual > good reasons? No... I could live with some globals. Althought I would probably use a static factory method to return an Interface instance. My problem is, that I don't know how to make my C++ classes, which are linked to plugin.so, available to ruby which is embedded by plugin.so. A usal ruby extension would just load the extension from a lib. But in my case the lib containing the extension itself is running the ruby script Lets say, I have interface.h which defines a C++ class "Interface" with a static methode that returns a singleton instance of this class. It may get the instance from a global variable. SWIG now creates an interface_wrap.c, which I compile and link to my plugin.so. Within the plugin.so some methode should now run the ruby script, calling ruby_init and all the stuff to handle exceptions and so on. But how do I let the ruby script know, that there is a class "Interface"? A simple 'require "interface"' doesn't work. Tobias