Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-04-24 06:12:10


----- Original Message -----
From: "Sam Holden" <sholden_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, April 24, 2001 1:42 AM
Subject: [boost] Help with boost::python...

> I'm planning on embedding python in a C++ project I'm starting. I have
> done a little of this before, but I've never tried it with boost::python.
<snip>
> Basically an abstract interface and an implementation (more than one in
> reality). In reality the abstract interface has some implementation but
> also contains pure virtual member functions which return references to
> classes with pure virtual member functions.
>
> I wish to export these classes to python using boost::python.
>
> The best I can get is the Derived class working but when I call d.result()
> in python I end up getting a Base_Result object back which calls the
> Base classes member function (which I had to implement...)
>
> So does anyone have any experience in getting something similar to work,
> and could point me in the right direction?

With the current version of boost::python, you'd need to hold the
Derived_Result with a boost::shared_ptr (or equivalent) instead of embedding
it by value, or resort to "dangerous hacks" as described in
http://www.boost.org/libs/python/doc/pointers.html

Every few months somebody asks this question. I posted a proposed resolution
at
http://groups.yahoo.com/group/boost/message/10144, which I would implement
if I got enough positive feedback. Unfortunately, the thread starting with
http://groups.yahoo.com/group/boost/message/10479 was the only result, and
was inconclusive. If my proposal would fill your needs, let me know it. One
more voice in favor of the original proposal would help tip the scales.

> Also does boost::python work OK for embedding python as opposed to
extending
> python? Can I statically link in the extensions for example?

Yes, but I don't think we have an example of in the code anywhere. However,
others have made it work.

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk