new_array


The new_array function is a non-class version of the CArray:new method which creates and returns a new CArray object.

Syntax

A = new_array()

bullet.gif    Default constructor. The new CArray A has no elements.

A = new_array( CArray_old )

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

A = new_array( n, val )

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

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 = new_array()

-- 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 example shows the use of all 3 constructors: default, copy, and initialization:

A1 = new_array( 5, 1.0 )

-- initialization constructor

A1[3] = 5

-- modify the value of A at index 3

A = new_array(A1)

-- copy constructor

B1 = new_array()

-- default constructor

B1:Init( 3, 2.0 )

-- define B indices 1, 2, 3

B = new_array(B1)

-- shows Copy constructor

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

-- result: AdotB = 12

Related Topics

CArray, Copy, new, delete

 


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