From: Lyle Johnson Date: 2003-05-07T01:27:59+09:00 Subject: Re: SWIG and Ruby (Was Re: SWIG on Solaris problem) Jeff Putsch wrote: > In a nutshell, yes. Basically, the C data structures used by > your application, in this case Cadence's itkDB, do not (or may > not) map to ruby objects in a manner you will find convenient > or natural to use. I *was* wondering whose API Jim was working with ;) > For example, itkDB has places it returns *dbPathStyle as an > output. Without special typemaps, these come back into Ruby > as a generic object that we can pass around, but not really > know what the value is. In C, the results points to an > integer so we have a typemap that tells swig how to map this > type to a ruby Fixnum > > %typemap(ruby,argout) dbPathStyle *OUTPUT ... Ugh. Yes, I guess the upshot of all this is that if your C/C++ "looks" a lot like the final Ruby interface, you may not need to write too many typemaps (if any). But the weirder it gets, for whatever reason, the harder it may be to get SWIG to do something useful with it. As I said in my last post, this kind of interface will probably present at least as much of a challenge if you're writing the code yourself, by hand. One of the more difficult libraries I've dealt with (in terms of SWIGging it) is one that we use in my company. The library is written in C, but it must be usable from Fortran. Since Fortran passes all function arguments by reference (i.e. pointer), the public API for this library is a lot like the one Jeff is describing -- everything, even the inputs, are pointers instead of "plain old values". Remember, however, that wrapping C/C++ libraries with SWIG isn't an all-or-nothing proposition. For example, let's say this itkDB library has a total of 200 functions in its public interface, but you're only interested in wrapping a dozen of those functions. That's no problem, just list the functions of interest in your SWIG interface file (as you've already started doing) and ignore the rest. And of course as your needs change, you can add wrappers for other functions later.