Meaning#
Tables store key-value pairs. Sequence indices normally start at 1. object:run(x) means object.run(object, x): the colon passes self. A table does not automatically gain game methods.
Example#
local object = {count = 0}
function object:add(value)
self.count = self.count + value
end
object:add(2)
local values = {"a", "b"}
local text = table.concat(values, ", ")What happens: object.count = 2; text = "a, b"; the colon passes object as self.
This fragment does not print or write a log message. The values shown are the expected results of the example.
Methods and related calls#
| Function | Returns | Purpose |
|---|---|---|
| table.concat | string |
Joins string or numeric sequence elements with a separator. |
| table.insert | none |
Inserts a sequence value and shifts elements; an omitted position appends it. |
| table.remove | any | nil |
Removes and returns a sequence element, shifting later values; defaults to the last element. |
| table.sort | none |
Sorts a sequence in place; a comparator must define a strict order. |
| table.unpack | any, ... |
Expands a sequence range into multiple results; requires the compatibility extension to be available. |