new_valueset


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

Syntax

S = new_valueset()

bullet.gif    Default constructor. The value type is set "number" by default.

S = new_valueset("string")

bullet.gif    Constructs a CValueset object and sets the value type to "string".

S = new_valueset( CValueSetOld )

bullet.gif    Constructs a new CValueSet S and initializes it to the members of the existing CValueSetOld argument.

S = new_valueset( tbl )

bullet.gif    Constructs a new CValueSet S from a 1-dimensional array with values that are numbers. of pairs. The first member of each pair is the string kley and the second member is the value of type "number", "integer", "string", or "boolean".

bullet.gif    .On failure, nil is returned.

Example

The following example shows the use of a default constructor with no passed parameters. This defaults the value type to "number":

S = new_valueset()

-- create a new instance S of the CValueSet class.

  ...

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

S:delete()

-- deletes the object and its associated memory.

The following example creates a CValueSet S, adds members to it, then creates a second CValueSet containing the same members as the first set:

S = new_valueset()

-- constructor, default to values of type "number"

S:Add( "my first string", 15.5 )

-- add a key and value

S:Add( "my second string", -7125.23 )

-- add a key and value

S:Add( "my third string", 0.923 )

-- add a key and value

Printf("Count= %d", S:Count())

-- result: Count = 3

S2 = new_valueset(S)

-- create S2 and initialize it to members of S

Printf("Count= %d", S2:Count())

-- result: Count = 3

Printf("Type= %s", S:GetType())

-- result: "number"

The following example creates a new CValueSet from a 1-dimensional array with values that are numbers. of pairs. Each pair contains a key and a value. In this example, the values are strings. The new_valueset function determines that the values are strings by determining the type of value in the first member of the 1-dimensional array with values that are numbers.:

tbl = {}

-- create a 1-dimensional array with values that are numbers.

tbl[1] = {"first key", "Michael"}

--Assign a key and value to table[1]

tbl[2] = {"second key", "Rachel"}

-- Assign a key and value to table[2]

tbl[3] = {"third key", "Reginald"}

-- Assign a key and value to table[3]

tbl[4] = {"fourth key", "Cameron"}

-- Assign a key and value to table[4]

S = new_valueset(tbl)

-- create S from the 1-dimensional array with values that are numbers.

Printf("Count= %d", S:Count())

-- result: Count = 4

Printf("Type= %s", S:GetType())

-- result: "string"

Related Topics

CValueSet Class

new

delete

 


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