← 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

Feedback

For feedback, please check the contacts section. Before writing, please specify where you came from and who you are. Sometimes spammers go insane. Thank you in advance for your understanding.

← Back to the index page