[C++-sig] Boost Python: Howto wrap "out" arguments of a methode
Alexander Eisenhuth
newsuser at stacom-software.de
Wed Jun 6 08:02:27 CEST 2007
David Abrahams schrieb:
> on Mon Jun 04 2007, Alexander Eisenhuth <newsuser-AT-stacom-software.de> wrote:
>
>> How to wrap methode Get with Boost.Python?
>
> First, I suggest you take your question to the C++-sig
> (http://www.boost.org/more/mailing_lists.htm#cplussig).
>
>
>> class MyClass {
>> public:
>> MyClass();
>>
>> void GetX(double &pos_x);
>> [...]
>>
>>
>> I'v tried it with:
>>
>> .def(
>> "GetX"
>> , &::MyClass::GetX
>> , bp::arg("")
>> , bp::return_value_policy<bp::return_arg<1>() >()
>>
>> But when I try it in python:
>>
>> Boost.Python.ArgumentError: Python argument types in
>> MyClass.GetX(MyClass, int)
>> did not match C++ signature:
>> GetX(class MyClass::LedPosition_C {lvalue}, int {lvalue} )
>>
>> Any ideas?
>
> return_value_policy is only good for telling Boost.Python how to
> handle the actual (non-void) return value of your C++ function. In
> your case, create a thin wrapper function:
Ok, thanks for that hint.
>
> double GetX2(MyClass& self, double pos_x)
> { self.GetX(pos_x); return pos_x; }
>
> and wrap that instead of GetX:
>
> .def("GetX", GetX2)
>
So boost.python doesn't have a mechanism to transform in the wrapper code a call
by reference into return value?
More information about the Cplusplus-sig
mailing list