Skip to content

Commit dcbcba4

Browse files
author
Roberto De Ioris
committed
preliminary support for arrays
1 parent a012695 commit dcbcba4

3 files changed

Lines changed: 51 additions & 15 deletions

File tree

‎Source/UnrealEnginePython/Private/UEPyActor.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,9 @@ PyObject *py_ue_get_overlapping_actors(ue_PyUObject * self, PyObject * args) {
510510

511511
for (AActor *overlapping_actor : overalpping_actors) {
512512
ue_PyUObject *item = ue_get_python_wrapper(overlapping_actor);
513-
if (item)
513+
if (item) {
514514
PyList_Append(py_overlapping_actors, (PyObject *)item);
515+
}
515516
}
516517
return py_overlapping_actors;
517518
}

‎Source/UnrealEnginePython/Private/UEPyCallable.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ static PyObject* ue_pycallable_call(ue_PyCallable *self, PyObject *args, PyObjec
1717
self->u_target->IsPendingKillOrUnreachable()) {
1818
return PyErr_Format(PyExc_Exception, "UFunction/UObject is in invalid state for python callable");
1919
}
20+
2021
return py_ue_ufunction_call(self->u_function, self->u_target, args, 0);
2122
}
2223

‎Source/UnrealEnginePython/Private/UEPyModule.cpp‎

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,39 @@ PyObject *ue_py_convert_property(UProperty *prop, uint8 *buffer) {
735735
goto end;
736736
}
737737

738+
if (auto casted_prop = Cast<UArrayProperty>(prop)) {
739+
FScriptArrayHelper_InContainer array_helper(casted_prop, buffer);
740+
PyObject *py_list = PyList_New(0);
741+
UProperty *array_prop = casted_prop->Inner;
742+
if (array_prop->IsA<UStructProperty>()) {
743+
uint8 *array_buffer = (uint8 *)FMemory_Alloca(array_prop->GetSize());
744+
for (int i = 0; i < array_helper.Num(); i++) {
745+
array_prop->InitializeValue(array_buffer);
746+
array_prop->CopyCompleteValueFromScriptVM(array_buffer, array_helper.GetRawPtr(i));
747+
PyObject *item = ue_py_convert_property(array_prop, array_buffer);
748+
array_prop->DestroyValue(array_buffer);
749+
if (!item) {
750+
Py_DECREF(py_list);
751+
return NULL;
752+
}
753+
PyList_Append(py_list, item);
754+
Py_DECREF(item);
755+
}
756+
}
757+
else {
758+
for (int i = 0; i < array_helper.Num(); i++) {
759+
PyObject *item = ue_py_convert_property(array_prop, array_helper.GetRawPtr(i));
760+
if (!item) {
761+
Py_DECREF(py_list);
762+
return NULL;
763+
}
764+
PyList_Append(py_list, item);
765+
Py_DECREF(item);
766+
}
767+
}
768+
return py_list;
769+
}
770+
738771
return PyErr_Format(PyExc_Exception, "unsupported value type %s for property %s", TCHAR_TO_UTF8(*prop->GetClass()->GetName()), TCHAR_TO_UTF8(*prop->GetName()));
739772

740773
end:
@@ -758,20 +791,20 @@ bool ue_py_convert_pyobject(PyObject *py_obj, UProperty *prop, uint8 *buffer) {
758791
return true;
759792
}
760793

761-
if (PyLong_Check(py_obj)) {
762-
auto casted_prop = Cast<UIntProperty>(prop);
763-
if (!casted_prop)
764-
return false;
765-
casted_prop->SetPropertyValue_InContainer(buffer, PyLong_AsLong(py_obj));
766-
return true;
767-
}
768-
769-
if (PyFloat_Check(py_obj)) {
770-
auto casted_prop = Cast<UFloatProperty>(prop);
771-
if (!casted_prop)
772-
return false;
773-
casted_prop->SetPropertyValue_InContainer(buffer, PyFloat_AsDouble(py_obj));
774-
return true;
794+
if (PyNumber_Check(py_obj)) {
795+
if (auto casted_prop = Cast<UIntProperty>(prop)) {
796+
PyObject *py_long = PyNumber_Long(py_obj);
797+
casted_prop->SetPropertyValue_InContainer(buffer, PyLong_AsLong(py_long));
798+
Py_DECREF(py_long);
799+
return true;
800+
}
801+
if (auto casted_prop = Cast<UFloatProperty>(prop)) {
802+
PyObject *py_float = PyNumber_Float(py_obj);
803+
casted_prop->SetPropertyValue_InContainer(buffer, PyFloat_AsDouble(py_float));
804+
Py_DECREF(py_float);
805+
return true;
806+
}
807+
return false;
775808
}
776809

777810
if (PyUnicode_Check(py_obj)) {
@@ -902,6 +935,7 @@ void ue_autobind_events_for_pyclass(ue_PyUObject *u_obj, PyObject *py_class) {
902935
}
903936

904937
PyObject *py_ue_ufunction_call(UFunction *u_function, UObject *u_obj, PyObject *args, int argn) {
938+
905939
uint8 *buffer = (uint8 *)FMemory_Alloca(u_function->ParmsSize);
906940

907941
Py_ssize_t tuple_len = PyTuple_Size(args);

0 commit comments

Comments
 (0)