Recently, "Thomas Heller" <thomas.heller@ion-tof.com> said: > Here's an outline which could work in 2.2: This sounds very good! There's only one thing you'll have to explain to me: how would this work from C? My types are all in C, not in Python, so I'd need to do the magic in C. Where do I find examples of using metatypes from C? I could then put all this wrapper stuff in a file WrapperObject.c and it would be reusable by any object that wanted this functionality. > Create a subtype of type, having a tp_convert slot: > > typedef int (*convert_func)(PyTypeObject *, void **); > > typedef struct { > PyTypeObject type; > convert_func tp_convert; > } WrapperTypeType; > > and use it as metaclass (metatype?) for your WindowObj: > > class WindowObj(...): > __metaclass__ = WrapperTypeType > > Write a function to return a conversion function: > > convert_func *get_converter(PyTypeObject *type) > { > if (WrapperTypeType_Check(type)) > return ((WrapperTypeType *)type)->tp_convert; > /* code to check additional types and return their converters */ > .... > } > > and then > > if (!PyArg_ParseTuple(args, "O&", get_converter(WinObj_Type), &Window)) > > How does this sound? > > Thomas > > -- - Jack Jansen <Jack.Jansen@oratrix.com> http://www.cwi.nl/~jack - - If I can't dance I don't want to be part of your revolution -- Emma Goldman -
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4