From: Dennis Newbold Date: 2002-03-29T09:12:19+09:00 Subject: Re: Ruby SWIG problems Hi James, I've noticed a similar when trying to create a wrapper for C program. I finally wound up using the skeleton produced by SWIG, and writing my own code inside each "wrapper", then deleting all the SWIG-related small service routines that were no longer called by anyone. From the short time that I spent looking at it, I think that the problem is that SWIG thinks that all VALUES contain pointers to the real data, and tries to get the pointer, and extract the real data. So, it may work fine when used to wrap routines that receive arrays, hashes, and strings, but will not work too well for routines that expect FixNum's and booleans. FWIW. For my purposes, it was easier to work around it than to try to get the attention and time of somebody on the SWIG project, and get him to fix SWIG. If you have alot (e.g., 100 or so) routines that you are trying to get SWIG to build wrappers for, you may find it worth your while to try to go in and hack the SWIG support routines that all of the wrapped code depends on. Your call. Good luck. Dennis Newbold On Thu, 28 Mar 2002, James Adam wrote: > Hi > > I've been trying to use Ruby SWIG, but been having limited success. > Currently I'm using SWIG 1.3.11, and Ruby 1.7.2 ('stable' ruby versions have > given me even less success than below). Here's the scoop: > > i've got 3 files: > > /* File : example.h -------------------*/ > > class TestClass { > public: > TestClass(); > int result; > > int add(int x, int y); > }; > > /* File : example.cxx ------------------*/ > > #include "example.h" > > TestClass::TestClass() { > result = 0; > } > > int TestClass::add(int x, int y) { > result = x + y; > return result; > }; > > /* File : example.i ----------------------*/ > %module example > %include example.h > > /*---------------------------------------*/ > > ....and i run the following commands, all via cygwin (Ruby & SWIG both also > compiled using cygwin): > > $ swig -c++ -ruby example.i > $ gcc -c example.cxx > $ gcc -c example_wrap.cxx -I/usr/local/lib/ruby/1.6/i386-cygwin > $ gcc -shared example.o example_wrap.o -o example.so -lcygwin-ruby17 > > .... all with no errors. Now when i try and use my new module 'example' - i > get this: > > $ irb > TypeError: wrong argument type Fixnum (expected Class) > from (irb):1:in `require' > from (irb):1 > irb(main):002:0> > > Anyone have any ideas? I've tried using different class definitions, etc etc > but with no joy. > > Thanks > > James > > >