CMatrix:Dup
The Dup method duplicates the current CMatrix and returns the new object.
M = CMatrix:Dup() where |
M is a new CMatrix containing the same values as the current one.
This method copies an existing CMatrix and returns a reference to the new CMatrix. You cannot copy a CMatrix or other class object using the trivial statement B = A, as this simply makes the value of B a reference to the object A. In other words, B becomes an alias to A. To get around this, two copy methods are provided by the CMatrix class:
To create a CMatrix that is a copy of the current object, use the Dup method. This creates a new CMatrix B before duplicating the values of the current object A:
|
-- CMatrix A already exists |
To create a new CMatrix that is a copy of an existing object, use the copy constructor, as in
|
-- CMatrix A already exists |
Choose the syntax that fits best with your script.
The following script duplicates the CMatrix Mold into a new CMatrix Mnew:
|
-- create a new CMatrix |
|
-- set member 2, 44 |
|
-- set member 50, 20 |
|
-- set member 120, 2 |
|
-- create a duplicate M2 |
|
-- result: N= 3,3 |