From: Alex Fenton Date: 2008-12-12T23:28:10+09:00 Subject: Re: Q: FFI and C++? Jeremy Henty wrote: > On 2008-12-11, Alex Fenton wrote: > >> Latest SWIG does include C as a target language. In other words it >> can generate ANSI C wrapper code around C++ classes / libraries. > > Very interesting! Thanks. > >> SWIG can also output a parse of C++ classes and methods to XML. But >> if this is all you want to do, probably the Rb++ route is better as >> it has existing Ruby classes for making use of the parse. I guess in >> theory you might also be able to generate the FFI code from this at >> the same time. > > That's my plan, but SWIG is an interesting option too. Once you've had a chance to try things out, I'd be very interested in hearing about your experiences. I work on the bindings for a large C++ library (wxWidgets) and I'm looking at options for the next version. We use SWIG at the moment to generate a (MRI-only) wrapper, but this means that hacking on the core library is a daunting prospect (SWIG is powerful but complex, C++ is hard and requires a compiler). I looked a Rb++ for the whole work but there didn't seem to be enough gain for the pain of switching over a large code base. SWIG deals with several C++ features that aren't supported in Rb++ as far as I can tell: overloaded methods, implementing virtual methods in Ruby, keeping a one-to-one link between Ruby instances and C++ objects. So I'm keen to find out if there's a way of reducing the complexity of the SWIG/C++ code and doing more of the wrapping work in Ruby - as well as being able to potentially run wxRuby on JRuby. a