From: Rick Bradley Date: 2002-05-07T02:55:41+09:00 Subject: Re: Embedding Ruby in C++ * jared l. jennings (jjenning@stetson.edu) [020506 12:46]: > this is how i thought of it: you wrap the classes you want to get at in > ruby. now, instead of using 'require' to bring them in from a .so, you > compile the wrappers into the C++ program. When the program runs, it > initializes the ruby interpreter which it embeds, then calls the Init > function for the wrapper, thus making the wrapped classes available to > the embedded Ruby. Then in C++ when you want to get at objects created > or modified by Ruby, you get a VALUE for them, and... ahm... i think you'd > have to look at the wrapper code, but i think SWIG makes a struct that > has a pointer to the C++ object. somewhere in there there is a pointer > you can snag. so you can mess with the object, and the changes are > visible to the embedded Ruby. you can frob it in ruby, and see changes > in C++. both in an object-oriented way without an overage of C-writing. I used to do a lot of embedding of Perl into C/C++ and C/C++ into Perl, using SWIG for the latter (actually once I had a C program embed a Perl interpreter which called SWIG'ed C extensions, but it was not something I wanted to do a lot of). At least there (I don't know how it's done w/ Ruby) if you wanted to embed the Perl interpreter into a C/C++ application you included an .h file in your C/C++ source, used some macros to initialize the interpreter, and used some more macros to call Perl routines and pass values back and forth. You linked with -lperl (IIRC) and ended up with a big gnarly binary. This is the direction I think the original poster was wanting to go -- and I'm curious how to do the same thing with Ruby myself. Going the other way (what I'm reading you as saying) one writes some C/C++ code and then would like to call that functionality from Ruby, uses SWIG to generate the proper stubs, compiles the stubs+C/C++ and then does a require from Ruby. Rick -- http://www.rickbradley.com MUPRN: 258 (89 F) | another set of random email haiku | neurons I'll volunteer mine. | On the email front...