Sign in to follow this  

Extracting parent object from boost.python

This topic is 4205 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If there is any simple way of doing this I would be greatfull. Say I have a class Entity and in python derives a new class named Player Now I pass this (player instance not class type) class from python to a function in c++ that expects a boost::python::object Now what I want is to get a pointer to the Entity object part of Player. Lets me show you with a bit of example code:
void foo( py::object p_object )
{
      // the object passed into this function is a Player class
    Entity* e_tmp = (Entity*)p_object.rawpointer();

    e_tmp->ThisFunctionIsNotExposedToPython();
}
Now what I want is to have somthing in the lines of the '.rawpointer()'. How can I achive this effect in boost.python?

Share this post


Link to post
Share on other sites
You should be able to use boost::python::extract<>() to get a pointer to the type that you registered. The exact syntax would depend on how you registered the class.

Share this post


Link to post
Share on other sites
When using the default registration mechanism (without specifying a HeldType), it's probably best to extract by reference. Ex:

GameState & gs = extract<GameState &>(python_object);

Share this post


Link to post
Share on other sites

This topic is 4205 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this