Skip to content

Commit

Permalink
add copy methods to wrapped struct
Browse files Browse the repository at this point in the history
  • Loading branch information
apple1417 committed Jan 14, 2025
1 parent 1354f59 commit 2ce96e5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/pyunrealsdk/unreal_bindings/wrapped_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
18 changes: 18 additions & 0 deletions stubs/unrealsdk/unreal/_wrapped_struct.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2ce96e5

Please sign in to comment.