diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-12-17 10:58:19 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-12-17 10:58:19 +0400 |
commit | c92dd5fa40c03dd677c4cd24fa905e25b7cf0d52 (patch) | |
tree | 3a9b824b3374b2248d69f0fcfcde80245e8a2301 /source/blender | |
parent | 18cb2d208c80c9abf884e51c9e7c6f822c811190 (diff) |
bpy/rna api: add support for classmethods.
So RNA can expose functions from the type, eg:
bpy.types.Objects.some_function()
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index a0df8988068..fbdcc86c425 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1478,7 +1478,7 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const cha } -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 @@ static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna) 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 */ } |