[C++-sig] Custom smart pointer and bp::wrapper

Paul Melis pyplusplus at assumetheposition.nl
Sun Jan 18 11:58:46 CET 2009


Roman Yakovenko wrote:
> 2009/1/17 Paul Melis <pyplusplus at assumetheposition.nl>:
>   
>> But when trying to run
>>
>> import doh
>>
>> class MyCallback(doh.Callback):
>>    def execute(self, t):
>>        print t
>>        return 1
>>
>> m = MyCallback()
>>
>> t = doh.Thing()
>> t.setCallback(m)
>> t.update()
>>
>> i'm getting
>>
>> Traceback (most recent call last):
>>  File "no_to_python_converter.py", line 12, in <module>
>>    t.update()
>> TypeError: No to_python (by-value) converter found for C++ type: Thing".
>>
>> And I fail to see why...
>>     
>
> Mu guess: you need to use boost::python::register_ptr_to_python< Thin >();
> ( http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/register_ptr_to_python.html
> )
>   
Well, that only seems to work on smart pointers, i.e. ref_ptr<Thing>.
>From the docs:
"|<boost/python/register_ptr_to_python.hpp>| supplies
|register_ptr_to_python|, a function template which registers a
conversion for smart pointers to Python"
> I have more or less complete example, which exports custom pointer
> class and its usage to Python:
> http://www.language-binding.net/pyplusplus/troubleshooting_guide/smart_ptrs/smart_ptrs.html
>   
Right, I did find it while trying to solve the above. But where our code
differs is that my wrapper class (CallbackWrap) needs to pass a Thing*
to Python and that's where it goes wrong. Your wrapper only returns an
integer and doesn't pass any parameters to Python. I think that is the
crucial difference here.

Regards,
Paul
 


More information about the Cplusplus-sig mailing list