Custom RTTI for use in script-defined types

旧街凉风 提交于 2019-12-04 19:36:33

I'm not familiar with boost::python; it might have some feature that makes this easier. I just know of a custom RTTI system that works pretty well:

Qt has a meta-object system, where reflection and a degree of dynamic behavior is added by having a metaobject associated with each class that knows about that class's ancestors and methods. It's kind of like Python's class objects. A virtual method is used to get the metaobject from instances. A custom compiler is used to generate these.

Qt's Python bindings then also create these metaobjects for Python classes, making them look almost identical to native QObjects classes as far as the meta-object system is concerned.


You need quite a bit less than Qt's general solution (you don't need info about methods/properties). So instead of a custom compiler, you could go with a C++-class definition macro that stores information about the class's ancestors. And then also update the information from the __metaclass__ when a Python subclass is created, and query it when you're dispatching a message.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!