Skip to content

Commit 0955dd0

Browse files
author
Roberto De Ioris
committed
added as_dict() to structs, fixed #200
1 parent f44ca2b commit 0955dd0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Source/UnrealEnginePython/Private/UEPyUScriptStruct.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,29 @@ static PyObject *py_ue_uscriptstruct_clone(ue_PyUScriptStruct *self, PyObject *
6363
return py_ue_new_uscriptstruct(self->u_struct, self->data);
6464
}
6565

66+
PyObject *py_ue_uscriptstruct_as_dict(ue_PyUScriptStruct * self, PyObject * args) {
67+
68+
PyObject *py_struct_dict = PyDict_New();
69+
TFieldIterator<UProperty> SArgs(self->u_struct);
70+
for (; SArgs; ++SArgs) {
71+
PyObject *struct_value = ue_py_convert_property(*SArgs, self->data);
72+
if (!struct_value) {
73+
Py_DECREF(py_struct_dict);
74+
return NULL;
75+
}
76+
PyDict_SetItemString(py_struct_dict, TCHAR_TO_UTF8(*SArgs->GetName()), struct_value);
77+
}
78+
return py_struct_dict;
79+
}
80+
81+
6682
static PyMethodDef ue_PyUScriptStruct_methods[] = {
6783
{ "get_field", (PyCFunction)py_ue_uscriptstruct_get_field, METH_VARARGS, "" },
6884
{ "set_field", (PyCFunction)py_ue_uscriptstruct_set_field, METH_VARARGS, "" },
6985
{ "fields", (PyCFunction)py_ue_uscriptstruct_fields, METH_VARARGS, "" },
7086
{ "get_struct", (PyCFunction)py_ue_uscriptstruct_get_struct, METH_VARARGS, "" },
7187
{ "clone", (PyCFunction)py_ue_uscriptstruct_clone, METH_VARARGS, "" },
88+
{ "as_dict", (PyCFunction)py_ue_uscriptstruct_as_dict, METH_VARARGS, "" },
7289
{ NULL } /* Sentinel */
7390
};
7491

0 commit comments

Comments
 (0)