← Back to the index page

Tuple

A tuple is a data structure where values are ordered and unchangeable. In Lua, tuples are implemented as tables.

Nothing more to discuss here. In one phrase: in Lua language tuple is just a table and nothing extra needs to be implemented.

Consider:

local tuple = {
    42,
    true,
    "some value",
    { a = 2, b = 3 },
    nil,
    function()
        print("something")
    end,
}

-- Iterate
for i = 1, #tuple do
    print(i, tuple[i])
end
--Output:
-- 1 42
-- 2 true
-- 3 some value 
-- 4 table: 0x563597b49950 
-- 5 nil
-- 6 function: 0x563597b45ba0

References

← Back to the index page