From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2002-08-04T12:36:46+09:00 Subject: Re: embed or swig? In article <20020803231558.GA11531@prism.localnet>, Massimiliano Mirra wrote: >On Sun, Aug 04, 2002 at 07:56:21AM +0900, Phil Tomson wrote: >> We started off wanting to do unit testing of our C++ classes so I tried >> out Swig1.3.13 to wrap our classes. Let's say you have three classes, >> we'll call them Line, Polygon and Point and let's say you want to have >> them live in a namespace called Geo. You would define an interface file >> as an input to swig that would looks something like: >> >> %module Geo >> %{ >> #include "Line.h"; >> #include "Polygon.h"; >> #include "Point.h"; >> %} >> %include "Line.h"; >> %include "Polygon.h"; >> %include "Point.h"; >> >> //end of Geo.i (probably not completely right, I'm doing from >> memory) > >Wait a minute. Do you really mean that, after you've written your C++ >classes, you just feed nine lines to Swig and after some crunching you > >have them available in Ruby? Or are you just simplifying? > Well, that is a bit simplified, though there are cases where that would probably be true. In reality you'll probaby have to write some typemaps - In the example above I show the the constructor for Geo::Polygon is taking a Ruby array of Lines - you'd probably have to write a typemape for that. Also, C++ allows method names to be overloaded based on differing argument lists, Ruby doesn't so you would have to use swig's %rename (see the docs for details). But other than that swig is actually pretty easy to use. Phil