|
Boost Users : |
Subject: Re: [Boost-users] Exposing C++ Instances to Python
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-05-25 12:14:23
AMDG
Leonhard Weber 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?
>
Since you take a pointer, the pointer will be copied, the
object that it points to won't be copied. However,
you should probably make the argument a shared_ptr.
Otherwise, you'll run into trouble because the new shared_ptr
thinks that it has exclusive ownership.
In Christ,
Steven Watanabe
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