Eyeon:Script/Reference/Language/Tables
From VFXPedia
Contents |
What Are Tables?
Tables are essentially containers for values and variables. A table can contain any number of identifier/value pairs, and the value can be any type of data in eyeonScript - including strings, numbers, other tables, functions and userdata.
In the simplest form tables are constructed as shown in the following example, with each of the values listed between the curly braces being assigned to successive indices of the table. The curly braces are known as 'constructors', since they are what signals eyeonScript that a table is about to be created.
t = { "a", "b", "c", 100 }
To read back the values from the table in the above example we would access each value by its index:
print( t[1], t[2], t[3], t[4] )
Which would produce the output:
a b c 100
Indexed vs. Named Identifiers
Values assigned to a table can be given names as an identifier, instead of automatically assigned index number, as shown in the following example
t = { first = "a", second = "b", another = "c"}
To read back the values of a table which uses names as its index:
print( t["first"], t["second"], t["another"] )
which would produce the output:
a b c
It is also possible to refer to named values in a table using the format tbl.identifier, as shown below
print( tbl.first, tbl.second, tbl.another )
a b c
You can use both indexed and named identifiers in the same constructor, provided they are separated by a semi colon rather than a comma, as shown below
table2 = { first = "a"; 2, another = "c"}
If the last value in the list is a function, then all values returned by the function are added to the list.
Tables are the dominant data structure in eyeonScript, and most of the data returned by Fusion is arranged in tables.
Dynamic Tables
A table is dynamic - its identifier/value pairs do not have to be declared at the time of table construction, they can be added later. The example below demonstrates this feature.
t = {}
t.First = 1
t.Second = "two"
t[1] = 15