Count


The Count function returns the count of elements in a variable list that can include values, tables, and data collection objects.

Syntax

nCount = Count( ... )

where

-- is a variable list of numbers, tables, CImage, CArray, and CMatrix objects.

    nCount is the count (number) of elements in the list.

  

Since Lua implicitly converts string representations of numbers to numbers, the argument list and tables also may contain strings that can be converted to numbers.

Example

The following script returns the count of elements in a collection of tables and numbers. This example is fairly complex to demonstrate that the method works. Note that table t is used twice in the argument list just for testing purposes.

t0 = { 1.5e-4, 2, 3, 4 }

-- create atable

t1 = { 10, 11 }

-- create another table

t2 = { {26, t0}, {"27"}, 3 }

-- createsome subtables

t3 = { 4, "5", "6" }

-- create a table with strings as numbers

t = { t1, t2, t3 }

-- assemble tables into another table

n = Count( t, 2, 5, t, "6" )

-- call Count() with an argument list

Printf( "Count = %d\n", n )

-- Result: Count = 27

Related Topics

Variable Argument Functions

Table Functions