maxn
The maxn function returns the maximum value of a general lua table that may contain a multi-dimensional array or a mixture of numbers, strings, named keys, and sub-tables. Only numeric values found in the table are used in the calculation. The related max function returns the maximum value of a 1-dimensional array, CImage, or list of numbers. Since an array is a specific type of table that contains only numbers or sub-tables, this function can also be used for arrays.
nMax = maxn( tbl )
tbl is a general lua table.
nMax is returned as the maximum value found in tbl. If tbl contains no numbers, the huge negative number -1.e308 is returned.
The following script returns the maximum value for an ugly table:
|
-- create a table |
|
-- find the maximum |
|
-- Result: Max = 24 |
The next script returns the maximum value for a 2-dimensional array with no keys or non-numeric values:
|
-- setup a table of rows |
|
-- for each row |
|
-- create a column table |
|
-- for each column |
|
-- assign the value to the column |
|
|
|
-- assign the column table to the row |
|
|
|
-- calculate the maximum of the array of 12 elements |
|
-- Result: Max = 12 |
Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024
Mirametrics, Inc. All Rights Reserved.