Boost logo

Boost Users :

Subject: [Boost-users] boost::python::return_value_policy<bp::reference_existing_object>() is weakref in python?
From: Thomas Rab (thomas.rab_at_[hidden])
Date: 2011-03-19 03:39:11


I've used boost::python in the past, but this problem has me stumped. Here's
part of the class I'm having issues with:

        class Entity
{
public:
Entity();
~Entity();

//Call to check our collider against all entities that have "tag"
Collider* Collide(const std::string &tag);
};

and here is the boost::python code:

bp::class_< Entity_wrapper >( "Entity", bp::init< >() )
        .def(
            "Collide"
            , (::Monocle::Collider * ( ::Monocle::Entity::* )( ::std::string
const & ) )( &::Monocle::Entity::Collide )
            , ( bp::arg("tag") ),
bp::return_value_policy<bp::reference_existing_object>() )

In python if I do something like this:

collider = entity.Collision("Paddle")

collider is a weakref to 'type' Not a Collider. My other functions that
return pointers seem to be fine. Is it just the call policy I'm using? What
Collide does is call a static function ("Collide") of the Collision class,
which in turn returns a Collider* on success and NULL otherwise.

Any help would be appreciated! If you need anymore information, let me know!

-- 
Tom Rab


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