TList
The TList function lists the contents of a table or a simple value such as a string or number. This command is most useful for Lua tables. Every element of a table is listed in the format [key]=value. Nested, or multi-dimensional tables and data structures, including arrays, are supported. The difference between this function and List is that List prints only the array part of a table and does not list key names. For a quick look at an array's contents, use List.
TList( value )
where
value is a number, string, or table.
This function lists all table elements with {} around the table data. Each level of nested table is indented and bracketed with {} around the table content. This is shown in the examples below. Note that when retrieving a table having key names, rather than numeric array indicices, Lua does not necessarily return them in the order they appear in your table.
A table element entered as a value but with no key, is defined to be an array element and is automatically assigned a numeric index as its key. This is shown in the examples below. For example, in the first example, the first member of table t is the value 5 which has no explicit key. Therefore, 5 is automatically assigned array index 1 as can be seen in the script output.
The following script creates a complex table and lists its contents. Notice that this table has a nester array inside a nested table.
|
-- create a table |
|
-- list the table |
This script produces the output shown below. Notice that the array components are listed with their array key, like 1, 2, or 3. The non-array components (or the "hash" part of the table) is listed with key names such as d and A. Note that A is listed out of order, but there's nothing that can be done about that. Array indices always are listed in order.
In the next example, the table contains no key names. However, it contains a nested table. All entries are array indices.
|
-- create a table |
|
-- list the table |
The result is shown below. Note the nested table at array index [3]: