When types are displayed through Boost.Python, they are entered into the current scope . Some types can be used as the current area, for example, those that are represented with class_.
Here is a complete annotated example:
#include <boost/python.hpp>
struct Human
{
struct emotion
{
char joy;
};
};
BOOST_PYTHON_MODULE(example)
{
namespace python = boost::python;
{
python::scope in_human =
python::class_<Human>("Human");
python::class_<Human::emotion>("Emotion")
.add_property("joy", &Human::emotion::joy)
;
}
}
Interactive Python:
>>> import example
>>> e = example.Human.Emotion
>>> e
<class 'example.Emotion'>
>>> hasattr(e, 'joy')
True
source
share