From: Craig Files Date: 2001-07-26T07:19:13+09:00 Subject: [ruby-talk:18551] overloading [] in SWIG.i file Hi, Another SWIG question: I would like to overload the [] operator in my SWIG.i file, so far my only solution is to create new methods in the SWIG.i file and then overload the [] operator while in ruby. .... I have tried to use rb_define_method() to solve this, but am either using it incorrectly, or it does not work the way I think that it should. Thanks Craig Swig.i file: %module StringVector %{ #include #include "StringVector.h" %} class StringVector { public : StringVector(); ~StringVector(); void push_back(char *); char *back(); char *front(); int size(); }; %addmethods StringVector { char *get_item(int index) { return (*self)[index]; } void set_item(int index, char*value) { (*self)[index] = value; } } in a Ruby.rb file: module StringVector class StringVector def [] (index) return get_item(index) end def []= (index, value) return set_item(index, value) end end end -- ___________________________________________________________________________ Craig Files | / http://fccf0183l.ftc.agilent.com/~cfiles/ | __o / craig_files@agilent.com | \<, / ____________________________________________|_____()/ ()____/