Extracting parent object from boost.python

Started by
2 comments, last by SiCrane 17 years, 10 months ago
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?
- Me
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.
After some trying with extract I got it to work.

Ty !

[Edited by - CoMaNdore on June 13, 2006 10:33:37 AM]
- Me
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);

This topic is closed to new replies.

Advertisement