Many structural patterns can be built with tables: stacks, queues, sets, lists, graphs, etc. As such, a Lua table can resemble a dictionary, hashmap or associative array from other languages. table.insert isn’t restricted to inserting tables into other tables.Ī Lua table is a collection of key-value pairs where the keys are unique and neither the key nor the value is nil. The latter can have numerical indexes or any other valid data type. table.key = value is syntactic sugar for table = value, which inserts the item into the array’s map. Anything inserted into a table from table.insert has a numerical index. (object) = (value) table.insert inserts an element into an array with optionally a position to place it at. Several table functions and operators work only with sequences. n is determined as the last such key that is paired with a nil value. The (possibly empty) subset of a table that has key values of the number type that are integers from 1 to n is called a sequence. Assigning nil to the value obliterates the pair.
0 Comments
Leave a Reply. |