MIST deepCopy

From DCS World Wiki - Hoggitworld.com
Revision as of 22:50, 13 April 2018 by Grimes (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


mist.utils.deepCopy

Added with: Mist 1.0
Description
This function returns a "deep copy" of table, "deep" in that the copy recursively progresses down all "levels" of the table, and the copy shares the same metatables as the passed-in table. This function also correctly handles tables with cycles. This function is quite often useful because tables are passed by reference in Lua, not by value.
Syntax
table mist.utils.deepCopy(table table )
Valid Input Values:
any table
Return value:
table
Return example:
same as input table
Usage Examples:

do

newTable = mist.utils.deepCopy(originalTable)

end

Notes:
This code is from [1].

Explained Further in English: If a variable is declared to equal a table, Lua does not create a new table, it instead creates a new reference for the table. So now you have two references to the same table and of course, any change made to one reference will apply to the other reference. mist.utils.deepCopy gets around this by creating an entirely new table that is effectively a "clone" of the other table.

Related Functions
deepCopy, dostring, basicSerialize, serialize, serializeWithCycles, oneLineSerialize, tableShow

Scripting Engine

MIST Root Page