[C++-sig] Pyplusplus: Support for anonymous structs?
Roman Yakovenko
roman.yakovenko at gmail.com
Tue Jun 3 07:32:09 CEST 2008
On Mon, Jun 2, 2008 at 3:01 PM, Hans Meine
<meine at informatik.uni-hamburg.de> wrote:
> Hi Roman,
>
> after reporting to Gustavo that pybindgen does not support unnamed structs, I
> tried pyplusplus and found the same (OK, not the same - pyplusplus gracefully
> skips the members with the two warnings "Py++ can not export unnamed
> variables" and "Py++ can not export unnamed classes"). Actually, there are
> two problems:
>
> 1) py++ generates the following code, which does not mention the "low"
> and "high" members wrapped in the struct:
>
> bp::class_< Word >( "Word" )
> .def_readwrite( "word", &Word::word );
>
> This should be "easy to fix" - py++ would need to descend into the struct and
> add
> .def_readwrite( "low", &Word::low )
> .def_readwrite( "high", &Word::high )
py++ is not going support unnamed classes, unless someone will submit the patch.
Next code does the job (taken as-is from Python-Ogre project)
def fix_unnamed_classes( classes, namespace ):
for unnamed_cls in classes:
named_parent = unnamed_cls.parent
if not named_parent.name:
named_parent = named_parent.parent
if not named_parent or named_parent.ignore:
continue
for mvar in unnamed_cls.public_members:
if not mvar.name:
continue
if mvar.ignore:
continue
if declarations.is_array (mvar.type):
template = '''def_readonly("%(mvar)s",
&%(ns)s::%(parent)s::%(mvar)s)'''
else:
template = '''def_readwrite("%(mvar)s",
&%(ns)s::%(parent)s::%(mvar)s)'''
named_parent.add_code( template % dict( ns=namespace,
mvar=mvar.name, parent=named_parent.name ) )
It takes list of unnamed classes.
> However, the next problem is fatal:
>
> 2) boost::python::class_ only works for structs and classes, but not for
> unions. I am getting an error from is_polymorphic:
Thanks for bug reporting. I fixed this problem, by excluding unions
from being exposed :-)
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
More information about the Cplusplus-sig
mailing list