flattenn
The flattenn function "flattens" a general lua table to a 1-dimensional array. This procedure discards all table keys and sub-tables but retains all values as an indexed 1-dimensional array. Flattening is useful, for example, to access all table data without keys and without keeping track of accessing sub-tables.
In comparison, the flatten function retains only the numeric values from a general table.
new_array = flattenn( tbl )
tbl is a general lua table.
new_array is the flattened 1-dimensional array.
The following script flattens a complex, ugly table. The oiginal and flattened tables are listed below the script.
|
|
|
-- list the original table |
|
-- flattenn to 1-dimension |
|
-- list the result |
In the listing below, notice that all values are retained but the keys and sub-tables are removed.
|
|
{ [1]=6 [2]=-2 [3]=15 [4]="a" [5]= { [1]=5 [2]="b" } [c]="5.4" } |
{ [1]=6 [2]=-2 [3]=15 [4]="a" [5]=5 [6]="b" [7]="5.4" } |
Mira Pro x64 Script User's Guide, v.8.73 Copyright Ⓒ 2024
Mirametrics, Inc. All Rights Reserved.