Enum we want to expose:
// Nice enum! enum Foo { blah };
While exposing the enum itself couldn't be any simpler:
BOOST_PYTHON_MODULE(enum_test) { bp::enum_<Foo> enum_foo("Foo"); enum_foo.value("blah", blah); ...... adding
__doc__
is completly another story.First (silly) attempt:
... PyObject_SetAttrString(enum_foo.ptr(), "__doc__", PyString_FromString("Nice enum!")); };"It must work" I thought, but what I got on import then was far from satisfying:
TypeError: attribute '__doc__' of 'type' objects is not writable
After digging in Boost.Python, Python C API docs and harassing people at #python:
... PyTypeObject * pto = reinterpret_castThils looked really promising... and what? Nothing at all! Changing(enum_foo.ptr()); pto->tp_doc = "Nice enum!"; };
tp_doc
had no effect whatsoever, and only after some more digging, it turned out it was too late to change it and the right way is:... PyTypeObject * pto = reinterpret_castBoost.Python and Python C API are fun ;)(enum_foo.ptr()); PyDict_SetItemString(pto->tp_dict, "__doc__", PyString_FromString("Nice enum!")); };
No comments:
Post a Comment