[capi-sig] Creating type object dynamically in run-time

Mateusz Loskot mateusz at loskot.net
Thu May 10 19:01:09 CEST 2012


On 10 May 2012 17:38, Campbell Barton <ideasman42 at gmail.com> wrote:
> If speed of class creation is important (as it is for us). suggest to
> call type directly rather then evaluating a string every time and
> executing it - this is one way.
>
>
>                /* always use O not N when calling, N causes refcount errors */
>                newclass = PyObject_CallFunction((PyObject *)&PyType_Type, (char
> *)"s(O) {sss()}",
>                                                 idname, py_base_class,
> "__module__", "bpy.types", "__slots__");
>
> which is like doing this in python...
>
>  type(idname, (py_base_class, ), dict(__module__="bpy.types", __slots__=()))

Campbell,

Thanks for the hint. It's good to know how the type() should be called from C.

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net


More information about the capi-sig mailing list