Hi James,
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? In addition, Ruby
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 nmae mangling scheme.
It seems like too much work for too little payback, if you ask me.
Course, thats just my take, and I don't know the "big picture" as you do.
Take care.
Dennis
---------------------------------------------
| |
| The way to be happy is to be good |
| |
---------------------------------------------
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
>
>
>