Skip to main content

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 BitSet128 objects
  • Isaac Color objects
  • Isaac KColor objects
  • Isaac RNG objects
  • Isaac Vector objects

It does not support:

  • objects with values of null (since that transpiles to nil)
  • other Isaac API objects such as EntityPtr (that have a type of "userdata")

Type parameters

Name
T

Parameters

NameTypeDescription
valueTThe primitive or object to copy.
serializationType?NONEOptional. 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?stringOptional. 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?booleanOptional. 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

NameType
valueunknown
serializationTypeSerializationType
traversalDescription?string
classConstructors?LuaMap<string, AnyClass>
insideMap?boolean

Returns

unknown

Defined in

packages/isaacscript-common/src/functions/deepCopy.ts:76