ismultidim
The ismultidim function returns true if a table contains any sub-tables, indicating that it is a "multi-dimensional" table. A 1-dimensional table returns false. This test may be useful for determining which functions to apply to a given table.
bIsTrue = ismultidim( tbl )
tbl is a general lua table.
bIsTrue is returned as boolean true of the table is multi-dimensional.
The following script tests whether a table has dimensionality greater than 1. The table t contains two sub-tables, and one sub-table contains another sub-table, hence the result is true. The booltostr function is used to convert the boolean result to a string
|
-- create a table |
|
-- test the dimensionality |
|
-- Result: Multi = true |
The next script creates a 2-dimensional array with no keys and no non-numeric values, Since it contains the sub-table col = {}, the test returns true:
|
-- 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 |
|
|
|
-- test the dimensionality |
|
-- Result: Multi = true |
The following table contains no sub-tables. Even though it contains a key and is therefore not an "array", it is not multi-dimensional, so the test returns false.
|
-- create a 1-dimensional table |
|
-- test the dimensionality |
|
-- Result: Multi = false |
Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024
Mirametrics, Inc. All Rights Reserved.