From: Tobias Grimm Date: 2004-08-21T07:37:11+09:00 Subject: Re: Overriding virtual C++ method in Ruby Lyle Johnson wrote: > Please read up on SWIG's cross-language polymorphism feature (a.k.a. > the "directors" feature), described here: Thanks for the hint, I missed this. But when enabling the directors feature some errors are raised. Very simple example: [foo.cc] class Foo { public: virtual char *test(void) { return "C++ implementation"; } virtual ~Foo() {}; }; [foo.i] %module(directors="1") ModFoo %feature("director") Foo; %include "foo.cc" [bar.rb] class Bar < ModFoo::Foo def test p "ruby implementation of test called" return "Ruby Implementation" end end $foo2 = Bar.new [main.cc] int main() { int state; ruby_init(); ruby_init_loadpath(); SWIG_init(); rb_load_protect(rb_str_new2("bar.rb"), Qfalse, &state); checkRubyError(state); Foo *foo1 = new Foo(); Foo *foo2; VALUE obj = rb_eval_string_protect("$foo2", &state); checkRubyError(state); rb_p(obj); Data_Get_Struct(obj, Foo, foo2); cout << "calling C++ implementation : " << foo1->test() << endl; cout << "calling Ruby implementation: " << foo2->test() << endl; ruby_finalize(); return 0; } [Output - directors feature disabled] # calling C++ implementation : C++ implementation calling Ruby implementation: C++ implementation [Output - directors feature enabled] # calling C++ implementation : C++ implementation "ruby implementation of test called" (eval): wrong argument type String (expected Data) (TypeError) (eval): [BUG] Segmentation fault ruby 1.8.1 (2004-02-03) [i386-linux] Where can the problem be? the test() implementation of the Ruby Bar-class gets called, but then something seems to go wrong with returning the string value. Tobias