From 2ce96e52cea8f722ec31dfe68cdae485d487b7e5 Mon Sep 17 00:00:00 2001 From: apple1417 Date: Tue, 14 Jan 2025 22:05:12 +1300 Subject: [PATCH] add copy methods to wrapped struct --- .../unreal_bindings/wrapped_struct.cpp | 16 ++++++++++++++++ stubs/unrealsdk/unreal/_wrapped_struct.pyi | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/pyunrealsdk/unreal_bindings/wrapped_struct.cpp b/src/pyunrealsdk/unreal_bindings/wrapped_struct.cpp index c110568..d435f94 100644 --- a/src/pyunrealsdk/unreal_bindings/wrapped_struct.cpp +++ b/src/pyunrealsdk/unreal_bindings/wrapped_struct.cpp @@ -212,6 +212,22 @@ void register_wrapped_struct(py::module_& mod) { " field: The field to set.\n" " value: The value to write.", "field"_a, "value"_a) + .def( + "__copy__", [](const WrappedStruct& self) { return WrappedStruct(self); }, + "Creates a copy of this struct. Don't call this directly, use copy.copy().\n" + "\n" + "Returns:\n" + " A new, python-owned copy of this struct.") + .def( + "__deepcopy__", + [](const WrappedStruct& self, const py::dict& /*memo*/) { return WrappedStruct(self); }, + "Creates a copy of this struct. Don't call this directly, use copy.deepcopy().\n" + "\n" + "Args:\n" + " memo: Opaque dict used by deepcopy internals." + "Returns:\n" + " A new, python-owned copy of this struct.", + "memo"_a) .def_readwrite("_type", &WrappedStruct::type); } diff --git a/stubs/unrealsdk/unreal/_wrapped_struct.pyi b/stubs/unrealsdk/unreal/_wrapped_struct.pyi index f3a7ff1..5d36f32 100644 --- a/stubs/unrealsdk/unreal/_wrapped_struct.pyi +++ b/stubs/unrealsdk/unreal/_wrapped_struct.pyi @@ -7,6 +7,24 @@ from ._uobject_children import UField, UFunction, UScriptStruct, UStruct class WrappedStruct: _type: UStruct + def __copy__(self) -> WrappedStruct: + """ + Creates a copy of this struct. Don't call this directly, use copy.copy(). + + Returns: + A new, python-owned copy of this struct. + """ + + def __deepcopy__(self, memo: dict[Any, Any]) -> WrappedStruct: + """ + Creates a copy of this struct. Don't call this directly, use copy.deepcopy(). + + Args: + memo: Opaque dict used by deepcopy internal + Returns: + A new, python-owned copy of this struct. + """ + def __dir__(self) -> list[str]: """ Gets the attributes which exist on this struct.