CSet:Copy


The Copy method duplicates the CSet and returns the new copy.

Syntax

S = CSet:Copy()

bullet.gif    S is a new CSet containing the same members as the current one.

Remarks

This method copies an existing CSet and returns a reference to the new CSet. You cannot copy a CSet 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 CSet class:

To create a CSet that is a copy of the current object, use the Copy method. This creates a new CSet B before duplicating the values of the current object. For example,

 

  B = A:Copy()

-- CSet A already exists

To create a new CSet that is a copy of an existing object, use the copy constructor, as in

 

  B = new_set(A)

-- CSet A already exists

You can use the copying syntax that fits best with your script.

Example

The following script duplicates a CSet.

S = new_set()

-- create a CSet

S:Append("First")

-- add a string to the set

S:Append("Second")

-- add a string to the set

S:Append("Third")

-- add a string to the set

T = S:Copy

-- creates a duplicate CSet named T

Printf("N= %d", T:Count())

-- Result: N = 3

Related Topics

CSet, new


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.