Jump to content
  • Advertisement
Sign in to follow this  
CoMaNdore

Extracting parent object from boost.python

This topic is 4421 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!