

del() removes the first element of the sequence that equals a given value, shifting all remaining elements down by one index to keep the sequence intact.add() appends a value to the end of a sequence.all(), which iterates over elements in the sequence in a table.PICO-8 provides several built-ins that operate on sequences: The # operator will only count those keys, ignoring any others present. The sequence part only consists of all numbered keys starting from 1 ascending up to the last key with a non-nil value. However, those keys are not considered part of the sequence. Note that a table containing a sequence is also allowed to have other keys. To avoid this problem, only make changes at the end of a sequence. There seems to be no consistent behavior. Lua uses associative arrays and which can. In some cases, Lua will recognize the change and will adjust the sequence. Tables are the only data structure available in Lua that helps us create different types like arrays and dictionaries. I have done a search and found information on table.insert but all the examples I have found seem to assume I only want numeric indices while what I want to do is add key pairs.
#Lua table insert key how to
add three more elements to the sequenceĬaution: If a key other than the final key is set to nil, or a key other than the next after the sequence is set to non-nil, the result is undefined. Just picking upon Lua and trying to figure out how to construct tables. Similarly, setting the next key to something non-nil will extend the sequence by 1, and this should always be done in forward order. Setting the final key(s) to nil is okay, because Lua will understand that they are being removed, and it will therefore reduce the length by by that many. Only contiguous keys at the end of the sequence should be cleared, in reverse order. No key in the middle of a sequence should ever be set/cleared to nil. Print("p is nil") - should print "p is nil" Lua offers special syntax and features so that sequences behave somewhat like lists or arrays in other languages.
#Lua table insert key series
PICO-8 provides the built-in pairs(), which iterates over all key-value pairs in a table.Ī sequence is a table with a contiguous series of numeric keys, starting with 1, each of which has a non-nil value. If the key is a string using the characters of a Lua identifier (letters, numbers, underscore, and begins with a letter), then the value can also be accessed using property notation ( tbl.key). Values can be accessed using bracket notation, where the key is an expression ( tbl). You can construct a new mapping using curly brackets. PICO-8 includes several built-in functions for using tables.įundamentally, tables are mappings of keys to values. Tables can be used as general purpose objects, and when combined with metatables (see Lua reference) can implement object-oriented concepts such as inheritance.


They are used as containers, especially sequences (with consecutive numeric indexes starting from 1) and mappings (also known as associative arrays, dictionaries, or hashtables). Tables are the primary composite data structure in the Lua programming language.
