List
The List function lists the contents of a variable list of objects consisting of numbers, strings, tables, etc. Tables may contain nested tables. Each value or table element is listed on a new line and table elements are intented at the level of the table.
List( ... )
where
... is a list of numbers, strings, tables, or other Lua types.
This function uses the Lua pairs function to access all table elements, without requiring each succesive table index to exist. As a result, the table elements are listed in an arbitrary order. Note that you do not need to use integral values as the table indices (see "blarney" in Example 1, below).
The following script creates a complex table and lists its contents. Of course, your tables need not be this complex:
|
|
|
-- table at index 5 has 3 random numbers |
|
-- table at index 3 has 4 random numbers |
|
-- create a subtable at table index 2 |
|
-- subtable is identical to t[5] |
|
-- subtable is identical to t[3] |
|
-- subtable at index 6 has 3 strings |
|
-- List the table and 2 other values |
The results from List() look as follows. Table element 3 is listed as [3], and so on. Each table level has a larger indent. Note that the table elements are not accessed in any particular order, which is normal when the table is not treated as an array:
[3]
{
0.894742
0.642079
0.824183
0.889676
}
[2]
{
[1]
{
0.320719
0.83578
0.686666
}
[blarney]
{
0.894742
0.642079
0.824183
0.889676
}
}
[6]
{
howdy
doody
time
}
[5]
{
0.320719
0.83578
0.686666
}
5
My string
The following script creates 2 tables and lists their contents.
|
-- table of 5 random values between 0 and 1 |
|
-- table of 5 random values between 10 and 20 |
|
-- list the tables |
The result from List() looks as follows. Note that each table has 5 elements:
0.1171
0.747124
0.616108
0.921049
0.203772
14.6348
17.5863
19.5666
16.9369
12.4473
The following script creates 2 tables and lists their contents with a label above each table. This is the same script as in example 2 except that a string is printed before each table which says what is listed below it.
|
-- table of 5 random values between 0 and 1 |
|
-- table of 5 random values between 10 and 20 |
|
-- also print a string before each table. |
The result from List() looks as follows.
X data
0.1171
0.747124
0.616108
0.921049
0.203772
Y data
14.6348
17.5863
19.5666
16.9369
12.4473