Tutorial by Examples

Creating an empty table is as simple as this: local empty_table = {} You can also create a table in the form of a simple array: local numeric_table = { "Eve", "Jim", "Peter" } -- numeric_table[1] is automatically "Eve", numeric_table[2] is "Ji...
The Lua standard library provides a pairs function which iterates over the keys and values of a table. When iterating with pairs there is no specified order for traversal, even if the keys of the table are numeric. for key, value in pairs(input_table) do print(key, " -- ", value) en...
Basic table usage includes accessing and assigning table elements, adding table content, and removing table content. These examples assume you know how to create tables. Accessing Elements Given the following table, local example_table = {"Nausea", "Heartburn", "Indigesti...
Defining our terms By array here we mean a Lua table used as a sequence. For example: -- Create a table to store the types of pets we like. local pets = {"dogs", "cats", "birds"} We're using this table as a sequence: a group of items keyed by integers. Many langua...

Page 1 of 1