From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2003-02-22T04:03:07+09:00 Subject: Re: Ruby-swig for C struct plus methods In article <3E562785.1080608@NASA.Gov>, Bil Kleb wrote: >We've been playing with testing a C-code via Ruby and testunit, >wrapping the C by hand. We've just recently tried using SWIG to >automate the wrapping, but so far we haven't found the right combination >for our situation. I've done what you're doing to unit test C++ classes. Swig worked great in that case. > >We have C-routines that look a lot like a C++ class, i.e., a struct >definition followed by associated methods where each method takes a >pointer to the associated struct as the first argument. > >The trouble is the C SWIG generator creates a class for the struct >and global module methods for the functions, and we've been unable >to figure out how to get the methods mixed into the class created by >the struct. > >Then again, maybe we're asking too much from SWIG's C-interface generator >and we should just embrace the latent object-oriented design of our curent >C code and migrate it to C++? Swig's a great tool, but you're probably right: you're asking a lot from it in this case. I would suggest moving to C++. From my experience, Swig will work very nicely for wrapping your C++ classes for unit testing in Ruby. > >Note: we'd also like to do some prototyping and possibly high-level >orchestration in Ruby in addition to merely using the test framework. I did exactly that on a project last summer. We started coding in C++ and I wanted to be able to setup a unit testing framework for our classes. I tried Cppunit but ended up using swig, Ruby and test::unit. Since all of our classes were available in Ruby, we also started using Ruby for the UI and to parse input and configuration files - so we used C++ for the stuff that had to go fast and Ruby for stuff that was a lot faster to develop in Ruby than it would have been in C++. The mixed language approach worked quite well. Phil