July 2018
Beginner
202 pages
5h 42m
English
Tables store values; a table is a relational data structure. This makes the table similar to a dictionary in other languages. To store a variable in a table, use the following syntax:
table[key] = value
The following example demonstrates how to make a table, store a value with the key x, and how to retrieve that value:
tbl = {}tbl["x"] = 20i = "x"print (tbl["x"])print (tbl[i])
The key of a table can be any type (even another table!), except for nil. This makes the following code valid—hard to read, but valid:
tbl = {}tbl["x"] = 10tbl[10] = "x"print ("x: " .. tbl["x"])print ("10: " .. tbl[10])
If you use a string key for a table, you can access it with the dot syntax. This syntax allows you to access the same data, but is easier ...