|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Another reference problemHi,
I've a problem passing a Python object to a method that expects a reference value, I read lots of previous messages but I couldn't find one that fit my situation so here is my problem: Python class: import mymodule as mm class PyFoo(mm.Foo): pass class PyBar(mm.Bar): pass pf = PyFoo() pb = PyBar() pb.test(0, pf) # the problem manifests here Foo and Bar are C++ classes and Bar::test has the following signature: void test(my_enum_type, Foo&); The error message I have is: TypeError: "in method Bar_test, argument 3 of type 'Foo &'" I tried to define a typemap like this: %typemap(directorin) (my_enum_type et, Foo &foo) { $1 = et; $2 = &foo; } but it looks like it's not taken into account. What should I do more ? Thanks, MD ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ Swig-user mailing list Swig-user@... https://lists.sourceforge.net/lists/listinfo/swig-user |
|
|
Re: Another reference problemMarco Dinacci wrote:
> Hi, > > I've a problem passing a Python object to a method that expects a > reference value, I read lots of previous messages but I couldn't find > one that fit my situation so here is my problem: > > Python class: > > import mymodule as mm > class PyFoo(mm.Foo): pass > class PyBar(mm.Bar): pass > > pf = PyFoo() > pb = PyBar() > pb.test(0, pf) # the problem manifests here > > Foo and Bar are C++ classes and Bar::test has the following signature: > > void test(my_enum_type, Foo&); > my_enum_type must be a global enum. You must also make sure that directors are turned on for the class and the test method, turn it on globally: %feature("director") ; The typemap must also be declared before SWIG parses test. Here is a full example: %module(directors="1") example %feature("director") ; %typemap(directorin) (my_enum_type et, Foo &foo) { // $input - $1 - "$1_name" - $2 - "$2_name" } %inline %{ class Foo { public: virtual ~Foo() {} }; enum my_enum_type { a, b }; class Bar { public: virtual ~Bar() {} virtual void test(my_enum_type et, Foo &foo) {} }; %} You'll have to fill in the contents of the directorin typemap with whatever you are hoping to achieve. > The error message I have is: > TypeError: "in method Bar_test, argument 3 of type 'Foo &'" > > I tried to define a typemap like this: > %typemap(directorin) (my_enum_type et, Foo &foo) { > $1 = et; > $2 = &foo; > } > For special variables, the python typemaps use $input and for some strange reason $1_name is used instead of $1. William ------------------------------------------------------------------------------ _______________________________________________ Swig-user mailing list Swig-user@... https://lists.sourceforge.net/lists/listinfo/swig-user |
| Free embeddable forum powered by Nabble | Forum Help |