CArray:MaxIndex CArray:Remove

CArray:new


The new method creates an instance of the CArray class. A CArray object may also be created using he non-class new_array function. Note: This method's name uses all lower case to present it as the analog of the C++ new operator. Generally, the names of class methods begin with an uppercase letter but new and delete are different.

Syntax

A = CArray:new()

bullet.gif    Default constructor. The new CArray A has no elements. The name CArray must be used with a colon to specify the type of new object to be created.

A = CArray:new( CArray_old )

bullet.gif    This is a copy constructor. The new CArray A is initialized to the properties of the CArray_old argument.

A = CArray:new( n, val )

bullet.gif    The new CArray A is initialized with the first n elements having the same value, val.

bullet.gif    The parameter n is an integral index in the array.

bullet.gif    The parameter val is optional and may be any type of Lua value. If omitted, it defaults to 0.0.

Example

The following example shows the default constructor and destructor pair:

A = CArray:new()

-- create a new instance of A of the CArray class.

  ...

-- other uses of the class go here, between new and delete.

A:delete()

-- deletes the object and its associated memory.

The next script shows the use of all 3 constructors: default, copy, and initialization:

A2 = CArray:new( 5, 1.0 )

-- initialize all elements to 1.0

A2[3] = 5

-- modify the value at index 3

A = CArray:new(A2)

-- copy constructor

B2 = CArray:new()

-- default constructor

B2:Init( 3, 2.0 )

-- define B indices 1, 2, 3

B = CArray:new(B2)

-- shows Copy constructor

Printf("AdotB = %lg", A:Dot(B) )

-- result: AdotB = 12

Related Topics

CArray

Copy

delete

new_array

 


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