From: Sean Middleditch Date: 2001-07-17T02:46:54+09:00 Subject: [ruby-talk:17940] Re: RUBY C++ Extension On Tue, Jul 17, 2001 at 01:54:18AM +0900, Bernhard Gl?ck wrote: > Does anybody have the source to a WORKING C++ Class exported to RUBY > (preferably using MSVC 6.0) ? > I would like to instantiate my C++ classes in RUBY just the way as in > C++ code. > All samples and docs I found are on straigt C Extensions and that does > not help much. I dunno how other people do it, but I wrap the C++ calls in C functions. Pass the C++ class pointer along with the Ruby object, cast it in the C function, and have it call the proper C++ method. I'm jsut beginning to get Ruby integrated as a scripting language in AweMUD, http://awemud.sourceforge.net if you want a simple example of this, although that code needs to be finished and heavily cleaned up. > > Also how can I export the overloaded operators (for addition etc..) > And very important can i mirror an inheritance relationship in RUBY ? > say i have a Ruby Method > world_add( Object ) which takes an object.. Object is a C++ Class. Now > i have a C++ class which is derived from Object. How do i export it to > Ruby so that the world_add method treats it just like the Object base > class ? This is pretty important to me. If I understand what you want, just wrap the C++ operators and calls in the C functions. Pass the derived object into the Ruby class, and the C function can cast it and call whatever method - using polymorphism everything should work fine. That's more or less how Ruby handles the Entity/Object/Character class in AweMUD. > Also my progam consists of more than one DLL in the main DLL i would > like to export the Object Base Class to ruby and in some plugin DLLs i > would like to export only classes derived from Object which can then > be added to a world with world_add ? DOes that work ? Over the DLL > boundary ? What to do to make it workt ? I'm a UNIX person, no clue there. Works in Linux shared objects, though. > Thanks in advance > Bernhard Gl?ck