ariovistus / pyd

Interoperability between Python and D
MIT License
157 stars 32 forks source link

Q: how to expose D class data member to Python? #152

Closed mw66 closed 3 years ago

mw66 commented 3 years ago

I'm following this doc, use Member!(fieldname):

https://github.com/ariovistus/pyd/blob/master/docs/source/classes.rst

to wrap Foo.m_i, at this line:

https://github.com/ariovistus/pyd/blob/master/examples/testdll/testdll.d#L170

        Member!("m_i"),

Then I do python3 setup.py build, it errors out:

/usr/local/lib/python3.6/dist-packages/pyd/infrastructure/pyd/make_wrapper.d(127): Error: no property shim for type pyd.struct_wrap.Member!"m_i"
/usr/local/lib/python3.6/dist-packages/pyd/infrastructure/pyd/make_wrapper.d(137): Error: template instance pyd.make_wrapper.class_decls!(0u, Foo, Member!"m_i", Init!int, Init!(int, int), Property!(i, Docstring!"A sample property of Foo."), BinaryOperatorX!("+", false, Guess), Def!(opSlice, PyName!"__iter__", Range function()), Def!(foo, Docstring!"A sample method of Foo."), Def!(a), Def!(b), Def!(c), Def!(d), Def!(e), Def!(f), Def!(g), Def!(h), Def!(j), Def!(k), Def!(l), Def!(m), Def!(n)) error instantiating

Can you provide an example how to do this?

Thanks.

mw66 commented 3 years ago

Just tried:

https://forum.dlang.org/post/ygavszimygeleajpdqbd@forum.dlang.org

        Member!("m_i", Mode!"rw"),

Still the same error:

/usr/local/lib/python3.6/dist-packages/pyd/infrastructure/pyd/make_wrapper.d(127): Error: no property shim for type pyd.struct_wrap.Member!("m_i", Mode!"rw")
/usr/local/lib/python3.6/dist-packages/pyd/infrastructure/pyd/make_wrapper.d(137): Error: template instance pyd.make_wrapper.class_decls!(0u, Foo, Member!("m_i", Mode!"rw"), Init!int, Init!(int, int), Property!(i, Docstring!"A sample property of Foo."), BinaryOperatorX!("+", false, Guess), Def!(opSlice, PyName!"__iter__", Range function()), Def!(foo, Docstring!"A sample method of Foo."), Def!(a), Def!(b), Def!(c), Def!(d), Def!(e),
 Def!(f), Def!(g), Def!(h), Def!(j), Def!(k), Def!(l), Def!(m), Def!(n)) error instantiating
mw66 commented 3 years ago

@ariovistus Thanks for the quick fix, can you make a new release? so I can fetch the new package from dub? Thanks!

ariovistus commented 3 years ago

0.14.1 is out

mw66 commented 3 years ago

https://forum.dlang.org/thread/tgieyptcldyjdztrrigg@forum.dlang.org

the release is tagged wrong. it should read "v0.14.1" instead of "0.14.1" to get recognized successfully.

@ariovistus

ariovistus commented 3 years ago

of course, the one time I don't look up the format..

try it now

mw66 commented 3 years ago

Thanks! it's working: https://code.dlang.org/packages/pyd