Boost logo

Boost Users :

Subject: Re: [Boost-users] Exposing C++ Instances to Python
From: XiongJia Le (lexiongjia_at_[hidden])
Date: 2010-05-25 12:16:13


Are you finding "Boost.Python.register_ptr_to_python" ?
Please look this document
http://www.boost.org/doc/libs/1_41_0/libs/python/doc/v2/register_ptr_to_python.html

Is this sample same as you require ?

Thanks,
Xiongjia Le ( http://notes.xj-labs.net/ )

On Tue, May 25, 2010 at 11:34 PM, Leonhard Weber <lweberk_at_[hidden]> wrote:

> Made a mistake... srry for my lacking knowledge/experience in C++. Trying
> to improve :D.
>
> For test purposes I changed the Python Script so it inits an instance, and
> then tries to fetch the instance through the PyCallback:
> #####
> from EngineCallback import *
>
> a = EngineCallback()
> b = PyCallback(a)
>
> >>> a
> <EngineCallback.EngineCallback object at 0x7ffbe74c5208>
> >>> b
> <EngineCallback.EngineCallback object at 0x7ffbe74b0050>
>
> #####
> On the C++ side I had to change this, its now passing the argument by value
> (which I dont want)
> shared_ptr<EngineCallback> PyCallback( EngineCallback* test ) { return
> shared_ptr<EngineCallback>(test); }
>
> If I passed it per reference EngineCallback* &test (hope Im getting the
> jargon right and not mixing up definitions) it would say:
>
>
> did not match C++ signature:
> PyCallback(EngineCallback* {lvalue})
>
> by changing it to pass by value it works, though isnt it making a copy of
> the instance? how do I get just a reference to the instance passed to
> Python?
>
>
>
>
> On 25 May 2010 16:56, Steven Watanabe <watanabesj_at_[hidden]> wrote:
>
>> AMDG
>>
>> Leonhard Weber wrote:
>>
>>> EngineCallback* test = new EngineCallback;
>>>
>>> // Entrypoint for Python to come ant fetch the Application Callback
>>> shared_ptr<EngineCallback> PyCallback( EngineCallback* &test );
>>> <snip>
>>>
>>> # test.py
>>> from EngineCallback import PyCallback
>>> from EngineCallback import EngineCallback
>>>
>>> test = PyCallback()
>>>
>>>
>>
>> PyCallback takes one argument. Hence the exception below.
>> Did you intend to use the global "test" instead of taking test
>> as an argument in PyCallback?
>>
>>
>> Traceback (most recent call last):
>>> File "test.py", line 5, in <module>
>>> test = PyCallback()
>>> Boost.Python.ArgumentError: Python argument types in
>>> EngineCallback.PyCallback()
>>> did not match C++ signature:
>>> PyCallback(EngineCallback* {lvalue})
>>>
>>>
>>
>> In Christ,
>> Steven Watanabe
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net