MIST deepCopy

From DCS World Wiki - Hoggitworld.com


Added with: Mist 1.0
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.
table mist.utils.deepCopy(table table )
Valid Input Values:
any table
Return value:
Return example:
same as input table
Usage Examples:


newTable = mist.utils.deepCopy(originalTable)


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