osdir.com
mailing list archive
Mozy Online Backup: 2GB Free. Automatic. Secure.

Subject: Re: Boost.Python : Byref parameters - msg#00297

List: python.c++

Date: Prev Next Index Thread: Prev Next Index
Joel Gerard wrote:

> .def("Normalize",VectorNormalize1)
> .def("Normalize",VectorNormalize2)
> .def("Normalize",VectorNormalize3)

You have to say .staticmethod("Normalize")

> Only Normalize defined by VectorNormalize3 is broken
> saying: "TypeError: unbound method
> Boost.Python.function object must be called with
> Vector instance as first argument (got float instance
> instead)"

They were wrapped as non-static methods thus require
a 'self' class instance argument first.

HTH,
Mike


Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

Boost.Python : Byref parameters

Hi All, I'm trying to call a C++ member function from Python that takes three ints by reference, and modifies them. static f32 Normalize (f32& fx, f32& fy, f32& fz); Furthermore, its overloaded: f32 Normalize (void); static f32 Normalize (Vector& kV); I've wrapped it like so: f32 (Vector::*VectorNormalize1)(void) = &Vector::Normalize; f32 (*VectorNormalize2)(Vector&)= &Vector::Normalize; f32 (*VectorNormalize3)(f32&,f32&,f32&) = &Vector::Normalize; .def("Normalize",VectorNormalize1) .def("Normalize",VectorNormalize2) .def("Normalize",VectorNormalize3) Only Normalize defined by VectorNormalize3 is broken saying: "TypeError: unbound method Boost.Python.function object must be called with Vector instance as first argument (got float instance instead)" I think I'm doing something wrong with the call-policies (since I have none), but I don't know which ones to use. What am I doing wrong? Can somebody explain what Boost is trying to do here? Thanks, Joel ===== -------------------------------------- Email: joelgerard@xxxxxxxxxx __________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com

Next Message by Date: click to view message preview

Re: Boost.Python : Byref parameters

"Mike Rovner" <mike@xxxxxxxxxx> writes: > Joel Gerard wrote: > >> .def("Normalize",VectorNormalize1) >> .def("Normalize",VectorNormalize2) >> .def("Normalize",VectorNormalize3) > > You have to say .staticmethod("Normalize") Well, except he has a static method overloaded with a non-static one, and Boost.Python doesn't really support that idiom (see thread at http://aspn.activestate.com/ASPN/Mail/Message/C++-sig/1811696). I suggest forgoing instance-less access for the static method as follows: f32 nonstatic_Normalize(Vector&, Vector& kV) { return Vector::Normalize(kV); } .def("Normalize",VectorNormalize1) .def("Normalize",nonstatic_Normalize) .def("Normalize",VectorNormalize3) You can also def() the static normalize at module scope: def("Normalize", VectorNormalize2); and then: >>> v = Vector() >>> Normalize(v) which in many ways is a more natural interface anyway. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com

Previous Message by Thread: click to view message preview

Boost.Python : Byref parameters

Hi All, I'm trying to call a C++ member function from Python that takes three ints by reference, and modifies them. static f32 Normalize (f32& fx, f32& fy, f32& fz); Furthermore, its overloaded: f32 Normalize (void); static f32 Normalize (Vector& kV); I've wrapped it like so: f32 (Vector::*VectorNormalize1)(void) = &Vector::Normalize; f32 (*VectorNormalize2)(Vector&)= &Vector::Normalize; f32 (*VectorNormalize3)(f32&,f32&,f32&) = &Vector::Normalize; .def("Normalize",VectorNormalize1) .def("Normalize",VectorNormalize2) .def("Normalize",VectorNormalize3) Only Normalize defined by VectorNormalize3 is broken saying: "TypeError: unbound method Boost.Python.function object must be called with Vector instance as first argument (got float instance instead)" I think I'm doing something wrong with the call-policies (since I have none), but I don't know which ones to use. What am I doing wrong? Can somebody explain what Boost is trying to do here? Thanks, Joel ===== -------------------------------------- Email: joelgerard@xxxxxxxxxx __________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com

Next Message by Thread: click to view message preview

Re: Boost.Python : Byref parameters

"Mike Rovner" <mike@xxxxxxxxxx> writes: > Joel Gerard wrote: > >> .def("Normalize",VectorNormalize1) >> .def("Normalize",VectorNormalize2) >> .def("Normalize",VectorNormalize3) > > You have to say .staticmethod("Normalize") Well, except he has a static method overloaded with a non-static one, and Boost.Python doesn't really support that idiom (see thread at http://aspn.activestate.com/ASPN/Mail/Message/C++-sig/1811696). I suggest forgoing instance-less access for the static method as follows: f32 nonstatic_Normalize(Vector&, Vector& kV) { return Vector::Normalize(kV); } .def("Normalize",VectorNormalize1) .def("Normalize",nonstatic_Normalize) .def("Normalize",VectorNormalize3) You can also def() the static normalize at module scope: def("Normalize", VectorNormalize2); and then: >>> v = Vector() >>> Normalize(v) which in many ways is a more natural interface anyway. HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by