Skip to content

Deep Copy

deepCopy<T>(value, serializationType?, traversalDescription?, classConstructors?, insideMap?): T

Defined in: packages/isaacscript-common/src/functions/deepCopy.ts:68

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”)

T

T

The primitive or object to copy.

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.

string

Optional. Used to track the current key that we are operating on for debugging purposes. Default is an empty string.

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.

boolean

Optional. Tracks whether the deep copy function is in the process of recursively copying a TSTL Map. Default is false.

T

deepCopy(value, serializationType, traversalDescription?, classConstructors?, insideMap?): unknown

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

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”)

unknown

The primitive or object to copy.

SerializationType

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.

string

Optional. Used to track the current key that we are operating on for debugging purposes. Default is an empty string.

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.

boolean

Optional. Tracks whether the deep copy function is in the process of recursively copying a TSTL Map. Default is false.

unknown