PyObject *py_ue_get_actor_components_by_type(ue_PyUObject * self, PyObject * args) { ue_py_check(self); PyObject *obj; if (!PyArg_ParseTuple(args, "O:get_actor_components_by_type", &obj)) { return NULL; } ue_PyUObject *py_obj = nullptr; if (ue_is_pyuobject(obj)) { py_obj = (ue_PyUObject *)obj; } // shortcut for finding class by string else if (PyUnicodeOrString_Check(obj)) { char *class_name = PyUnicode_AsUTF8(obj); UClass *u_class = FindObject<UClass>(ANY_PACKAGE, UTF8_TO_TCHAR(class_name)); if (u_class) { py_obj = ue_get_python_uobject(u_class); } } if (!py_obj) return PyErr_Format(PyExc_Exception, "argument is not a UObject"); if (!py_obj->ue_object->IsA<UClass>()) return PyErr_Format(PyExc_Exception, "argument is not a UClass"); AActor *actor = ue_get_actor(self); if (!actor) return PyErr_Format(PyExc_Exception, "uobject is not an AActor"); PyObject *components = PyList_New(0); for (UActorComponent *component : actor->GetComponentsByClass((UClass *)py_obj->ue_object)) { ue_PyUObject *item = ue_get_python_uobject(component); if (item) PyList_Append(components, (PyObject *)item); } return components; }
PyObject *py_ue_get_actor_component_by_type(ue_PyUObject * self, PyObject * args) { ue_py_check(self); PyObject *obj; if (!PyArg_ParseTuple(args, "O:get_actor_component_by_type", &obj)) { return NULL; } ue_PyUObject *py_obj = nullptr; if (ue_is_pyuobject(obj)) { py_obj = (ue_PyUObject *)obj; } // shortcut for finding class by string else if (PyUnicodeOrString_Check(obj)) { char *class_name = PyUnicode_AsUTF8(obj); UClass *u_class = FindObject<UClass>(ANY_PACKAGE, UTF8_TO_TCHAR(class_name)); if (u_class) { py_obj = ue_get_python_wrapper(u_class); } } if (!py_obj) return PyErr_Format(PyExc_Exception, "argument is not a UObject"); AActor *actor = ue_get_actor(self); if (!actor) return PyErr_Format(PyExc_Exception, "uobject is not an AActor"); if (!py_obj->ue_object->IsA<UClass>()) return PyErr_Format(PyExc_Exception, "argument is not a UClass"); UActorComponent *component = actor->GetComponentByClass((UClass *)py_obj->ue_object); if (component) { PyObject *ret = (PyObject *)ue_get_python_wrapper(component); if (!ret) return PyErr_Format(PyExc_Exception, "uobject is in invalid state"); Py_INCREF(ret); return ret; } Py_INCREF(Py_None); return Py_None; }
static int ue_PyUScriptStruct_setattro(ue_PyUScriptStruct *self, PyObject *attr_name, PyObject *value) { // first of all check for UProperty if (PyUnicodeOrString_Check(attr_name)) { char *attr = PyUnicode_AsUTF8(attr_name); // first check for property UProperty *u_property = get_field_from_name(self->u_struct, attr); if (u_property) { if (ue_py_convert_pyobject(value, u_property, self->data, 0)) { return 0; } PyErr_SetString(PyExc_ValueError, "invalid value for UProperty"); return -1; } } return PyObject_GenericSetAttr((PyObject *)self, attr_name, value); }
static PyObject *ue_PyUScriptStruct_getattro(ue_PyUScriptStruct *self, PyObject *attr_name) { PyObject *ret = PyObject_GenericGetAttr((PyObject *)self, attr_name); if (!ret) { if (PyUnicodeOrString_Check(attr_name)) { char *attr = PyUnicode_AsUTF8(attr_name); // first check for property UProperty *u_property = get_field_from_name(self->u_struct, attr); if (u_property) { // swallow previous exception PyErr_Clear(); return ue_py_convert_property(u_property, self->data, 0); } } } return ret; }
static PyObject *ue_PyEnumsImporter_getattro(ue_PyEnumsImporter *self, PyObject *attr_name) { PyObject *py_attr = PyObject_GenericGetAttr((PyObject *)self, attr_name); if (!py_attr) { if (PyUnicodeOrString_Check(attr_name)) { char *attr = PyUnicode_AsUTF8(attr_name); if (attr[0] != '_') { UEnum *u_enum = FindObject<UEnum>(ANY_PACKAGE, UTF8_TO_TCHAR(attr)); if (u_enum) { // swallow old exception PyErr_Clear(); Py_RETURN_UOBJECT(u_enum); } } } } return py_attr; }