t = CopyTable(src[, shallow])
Starting with Hollywood 6.0 this function accepts an optional argument
named shallow. If you set this argument to True, CopyTable() will
do a shallow copy of the table which means that instead of making an
independent copy, all sub-tables will only be copied by reference. A copy
by reference means that if the source table is modified, all copies
by reference will be modified as well. Shallow copies of a table have
the advantage that they save resources and they can also come in handy in
case of self-referential tables which would lead to a stack overflow
during a deep copy.
See Tables for details.
False) (V6.0)
t1 = {1, 2, 3, 4, 5}
t2 = t1
t2[0] = 10
DebugPrint(t1[0]) ; -> prints 10 because t2 is only a reference to t1
t3 = CopyTable(t1)
t3[0] = 20
DebugPrint(t1[0]) ; -> prints 10 now!
This code demonstrates first the copy-by-reference default behaviour of
Hollywood which only creates a reference to an existing table. Afterwards,
a deep copy is made using CopyTable().