bpy/rna api: add support for classmethods.

So RNA can expose functions from the type, eg:
  bpy.types.Objects.some_function()
This commit is contained in:
Campbell Barton 2012-12-17 06:58:19 +00:00
parent 18cb2d208c
commit c92dd5fa40
1 changed files with 23 additions and 1 deletions

View File

@ -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 */
}