list (replaces TList)


The list function lists the contents of a general lua table. Every table element is listed in the format [key]=value. If named key is not present, an integral subscript is assigned. Nested, or multi-dimensional tables are supported.

Syntax

list( value )

list( value, sTitle )

bullet.gif    value is lua table.

bullet.gif    sTitle is an optional title to appear above the listing.

Remarks

This function lists all table elements with {} around the values in each sub-table. As a consequence of the way lua stores table entries, both non-keyed values and keyed values specified with a numeric (integer) key are retrieved in index order. Keyed values are returned in an unspecified order.

Nested tables are each indented at the nesting level with enclosing {} to denote the table extent. See the example below.

Examples

The following script creates a complex multi-dimensional table and lists its contents. Notice that the printed list heading does not end with a newline ('\n') character because list() automatically prefixes the listing with a newline.

t = { 5, "My Name", A=1, 6, {x=1, y={2,r=3,4}}, 7 }

-- create a table

list( t, "listing of table t:" )

-- list table with a title

This script produces the output shown below. Notice that non-keyed array components are always listed first, in index order, within their respective table. The non-keyed ("array") elements such as 5 and "My Name" are listed first because they assume integral indices. The keyed (non-array) elements A=1 and r=3 are listed after the indexed elements in arbitrary order within their respective tables.

 

listing of table t:

{

  [1]=5

  [2]=My Name

  [3]=6

  [4]=

  {

    [x]=1

    [y]=

    {

      [1]=2

      [3]=4

      [r]=3

    }

  }

  [5]=7

  [A]=1

}

 

In the next example, the table contains no explicit key names and is considered to be a pure "array". Hence all elements assume integral indices in the order specified. The list is therefore in index order.

W = { 20,30,40 }

-- create a table

t = { 5, 200, W, 8 }

-- create a table

list( t )

-- list table without title

The list is shown below, Note the nested table W at array index 3. Also note that no title was specified:

 

{

  [1]=5

  [2]=200

  [3]=

  {

    [1]=20

    [2]=30

    [3]=40

  }

  [4]=8

}

 

Related Topics

Contents

Printf

Table and Array Functions

 


Mira Pro x64 Script User's Guide, v.8.80 Copyright Ⓒ 2025 Mirametrics, Inc. All Rights Reserved.