[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53074] trunk/blender/source/blender/ python/intern/bpy_rna.c: bpy/rna api: add support for classmethods.
Campbell Barton
ideasman42 at gmail.com
Mon Dec 17 07:58:22 CET 2012
Revision: 53074
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53074
Author: campbellbarton
Date: 2012-12-17 06:58:19 +0000 (Mon, 17 Dec 2012)
Log Message:
-----------
bpy/rna api: add support for classmethods.
So RNA can expose functions from the type, eg:
bpy.types.Objects.some_function()
Modified Paths:
--------------
trunk/blender/source/blender/python/intern/bpy_rna.c
Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c 2012-12-17 05:38:50 UTC (rev 53073)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c 2012-12-17 06:58:19 UTC (rev 53074)
@@ -1478,7 +1478,7 @@
}
-static PyObject *pyrna_func_to_py(PointerRNA *ptr, FunctionRNA *func)
+static PyObject *pyrna_func_to_py(const PointerRNA *ptr, FunctionRNA *func)
{
BPy_FunctionRNA *pyfunc = (BPy_FunctionRNA *) PyObject_NEW(BPy_FunctionRNA, &pyrna_func_Type);
pyfunc->ptr = *ptr;
@@ -6029,6 +6029,28 @@
PyObject_SetAttr(newclass, bpy_intern_str_bl_rna, item);
Py_DECREF(item);
+ /* add classmethods */
+ {
+ const ListBase *lb;
+ Link *link;
+
+ const PointerRNA func_ptr = {{NULL}, srna, NULL};
+
+ lb = RNA_struct_type_functions(srna);
+ for (link = lb->first; link; link = link->next) {
+ FunctionRNA *func = (FunctionRNA *)link;
+ const int flag = RNA_function_flag(func);
+ if ((flag & FUNC_NO_SELF) && /* is classmethod */
+ (flag & FUNC_REGISTER) == FALSE) /* is not for registration */
+ { /* is not for registration */
+ /* we may went to set the type of this later */
+ PyObject *func_py = pyrna_func_to_py(&func_ptr, func);
+ PyObject_SetAttrString(newclass, RNA_function_identifier(func), func_py);
+ Py_DECREF(func_py);
+ }
+ }
+ }
+
/* done with rna instance */
}
More information about the Bf-blender-cvs
mailing list