Blender V5.3
bpy_operator.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
15
16#include <Python.h>
17
18#include "../generic/python_compat.hh" /* IWYU pragma: keep. */
19
20#include "bpy_operator.hh"
22#include "bpy_operator_wrap.hh"
23
24#include "WM_api.hh"
25#include "WM_types.hh"
26
27namespace blender {
28
29/* -------------------------------------------------------------------- */
32
33static PyObject *pyop_dir(PyObject * /*self*/)
34{
36 PyObject *list = PyList_New(types.size());
37
38 int i = 0;
39 for (wmOperatorType *ot : types) {
40 PyList_SET_ITEM(list, i, PyUnicode_FromString(ot->idname));
41 i++;
42 }
43
44 return list;
45}
46
47#ifdef __GNUC__
48# ifdef __clang__
49# pragma clang diagnostic push
50# pragma clang diagnostic ignored "-Wcast-function-type"
51# else
52# pragma GCC diagnostic push
53# pragma GCC diagnostic ignored "-Wcast-function-type"
54# endif
55#endif
56
57static PyMethodDef bpy_ops_methods[] = {
58 {"dir", reinterpret_cast<PyCFunction>(pyop_dir), METH_NOARGS, nullptr},
59 {"get_rna_type", static_cast<PyCFunction>(pyop_getrna_type), METH_O, nullptr},
60 {"create_function", static_cast<PyCFunction>(pyop_create_function), METH_VARARGS, nullptr},
61 {"macro_define", static_cast<PyCFunction>(PYOP_wrap_macro_define), METH_VARARGS, nullptr},
62 {nullptr, nullptr, 0, nullptr},
63};
64
65#ifdef __GNUC__
66# ifdef __clang__
67# pragma clang diagnostic pop
68# else
69# pragma GCC diagnostic pop
70# endif
71#endif
72
73static PyModuleDef bpy_ops_module = {
74 /*m_base*/ PyModuleDef_HEAD_INIT,
75 /*m_name*/ "_bpy.ops",
76 /*m_doc*/ nullptr,
77 /*m_size*/ -1, /* multiple "initialization" just copies the module dict. */
78 /*m_methods*/ bpy_ops_methods,
79 /*m_slots*/ nullptr,
80 /*m_traverse*/ nullptr,
81 /*m_clear*/ nullptr,
82 /*m_free*/ nullptr,
83};
84
86{
87 PyObject *submodule;
88
89 if (BPyOpFunction_InitTypes() < 0) {
90 return nullptr;
91 }
92
93 submodule = PyModule_Create(&bpy_ops_module);
94
95 return submodule;
96}
97
99
100} // namespace blender
constexpr int64_t size() const
Definition BLI_span.hh:256
BMesh Iterators.
static PyObject * pyop_dir(PyObject *)
PyObject * BPY_operator_module()
Span< wmOperatorType * > WM_operatortypes_registered_get()
static PyMethodDef bpy_ops_methods[]
PyObject * PYOP_wrap_macro_define(PyObject *, PyObject *args)
PyObject * pyop_create_function(PyObject *, PyObject *args)
int BPyOpFunction_InitTypes()
static PyModuleDef bpy_ops_module
PyObject * pyop_getrna_type(PyObject *, PyObject *value)
header-only compatibility defines.