[C++-sig] Dynamic resolution of members and methods
Jérémie Delaitre
jeremie.delaitre at technogerma.fr
Wed Dec 10 17:08:55 CET 2008
Hello,
I have a C++ class that use a custom property system.
This property system allows me to add and remove properties at runtime.
I want to expose this class into Python.
The problem is: I want "a dynamic resolution" of the properties in Python.
For example:
# import my python extension
import myModule
# get an instance of my C++ class
t = myModule.newInstance()
# access the property 'myProperty'
print(t.myProperty)
When I access the property, I want python to call a "callback" of mine
(written
in the C++ extension) which will check if the requested property exists, and
if it does, return the corresponding value, otherwise generate an exception.
By looking at the python C API, I did not find a way to achieve this. It
seems
that declaring a new type requires to have static arrays for members and
methods
(yes, my property system allows me to declare new methods too, so I want
to expose
them with a similar system).
Any idea how I could resolve this (with Python3.0) ?
Regards,
Jérémie Delaitre
More information about the Cplusplus-sig
mailing list