From: Lyle Johnson Date: 2002-03-29T11:32:16+09:00 Subject: Re: Ruby SWIG problems > One final thought. I'm a little confused as to why you would > want to wrap a C++ class, when Ruby already supports classes. Wouldn't > it make more sense to declare the class in Ruby, and have each Ruby > method do its work by calling a regular C routine? SWIG's Ruby module looks at a C++ class declaration and generates wrapper code to: * define the class * define all of the class instance methods (and singleton methods, as appropriate) * convert input arguments from their Ruby types (e.g. strings, fixnums, floats) to the appropriate C++ types; * call the C++ member function on the correct C++ instance * convert the return value of that call from its C++ type to the appropriate Ruby type This is just the bare minimum of what SWIG does. A lot more is possible... > may not be able to properly connect to your C++ code due to name-mangling. > And, if you can figure out how to properly match the name mangling method > used by a given compiler, then you'll have problems porting it to a > different C++ compiler which may use a different name mangling scheme. OK, it's becoming increasingly obvious that you have never actually tried this. SWIG's output is straight C++ code. You compile that code with your C++ compiler. SWIG doesn't ever get involved with your compiler's "name mangling methods". > It seems like too much work for too little payback, if you ask me. For very small extensions, with a handful of methods, SWIG might indeed be overkill. But for any nontrivial project, and most any project involving wrapping C++ classes, I think most who have tried it would agree that it's worth the learning investment. > Course, that's just my take, and I don't know the "big picture" as you do. No comment ;)