From a6fc7180297f855c2592b20b26f96eb8e5a9e0ca Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 13 Sep 2018 18:16:06 +1000 Subject: PyAPI: add API call to get an operators type Getting the instance leaks memory and was only meant to be used for generating docs. --- source/blender/python/intern/bpy_operator.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source/blender/python/intern/bpy_operator.c') diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index 78ae9976586..555aec00b2c 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -409,6 +409,19 @@ static PyObject *pyop_dir(PyObject *UNUSED(self)) return list; } +static PyObject *pyop_getrna_type(PyObject *UNUSED(self), PyObject *value) +{ + wmOperatorType *ot; + if ((ot = ot_lookup_from_py_string(value, "get_rna_type")) == NULL) { + return NULL; + } + + PointerRNA ptr; + RNA_pointer_create(NULL, &RNA_Struct, ot->srna, &ptr); + BPy_StructRNA *pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); + return (PyObject *)pyrna; +} + static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value) { wmOperatorType *ot; @@ -466,6 +479,7 @@ static struct PyMethodDef bpy_ops_methods[] = { {"call", (PyCFunction) pyop_call, METH_VARARGS, NULL}, {"as_string", (PyCFunction) pyop_as_string, METH_VARARGS, NULL}, {"dir", (PyCFunction) pyop_dir, METH_NOARGS, NULL}, + {"get_rna_type", (PyCFunction) pyop_getrna_type, METH_O, NULL}, {"get_rna", (PyCFunction) pyop_getrna, METH_O, NULL}, /* only for introspection, leaks memory */ {"get_instance", (PyCFunction) pyop_getinstance, METH_O, NULL}, /* only for introspection, leaks memory */ {"macro_define", (PyCFunction) PYOP_wrap_macro_define, METH_VARARGS, NULL}, -- cgit v1.2.3