Deep Copy
Functions
deepCopy
▸ deepCopy<T>(value, serializationType?, traversalDescription?, classConstructors?, insideMap?): T
deepCopy is a semi-generic deep cloner. It will recursively copy all of the values so that none
of the nested references remain.
deepCopy is used by the IsaacScript save data manager to make a backup of your variables, so
that it can restore them to the default values at the beginning of a new room, floor, or run.
deepCopy supports the following object types:
- Primitives (i.e. strings, numbers, and booleans)
- Basic TSTL objects (which are the same thing as Lua tables)
- TSTL
Map - TSTL
Set - TSTL classes
DefaultMap- Isaac
BitSet128objects - Isaac
Colorobjects - Isaac
KColorobjects - Isaac
RNGobjects - Isaac
Vectorobjects
It does not support:
- objects with values of
null(since that transpiles tonil) - other Isaac API objects such as
EntityPtr(that have a type of "userdata")
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
value | T | The primitive or object to copy. |
serializationType? | NONE | Optional. Has 3 possible values. Can copy objects as-is, or can serialize objects to Lua tables, or can deserialize Lua tables to objects. Default is SerializationType.NONE. |
traversalDescription? | string | Optional. Used to track the current key that we are operating on for debugging purposes. Default is an empty string. |
classConstructors? | LuaMap<string, AnyClass> | Optional. A Lua table that maps the name of a user-defined TSTL class to its corresponding constructor. If the deepCopy function finds any user-defined TSTL classes when recursively iterating through the given object, it will use this map to instantiate a new class. Default is an empty Lua table. |
insideMap? | boolean | Optional. Tracks whether the deep copy function is in the process of recursively copying a TSTL Map. Default is false. |
Returns
T
Defined in
packages/isaacscript-common/src/functions/deepCopy.ts:68
▸ deepCopy(value, serializationType, traversalDescription?, classConstructors?, insideMap?): unknown
Parameters
| Name | Type |
|---|---|
value | unknown |
serializationType | SerializationType |
traversalDescription? | string |
classConstructors? | LuaMap<string, AnyClass> |
insideMap? | boolean |
Returns
unknown