Skip to content

Metatables #1

@tilkinsc

Description

@tilkinsc

Hey, creator of LuaConsole here!

Don't do this, but once I written a vector 2d class using metatables to capture invalid indexes of tables.

local tab = { pairs = {}, }
setmetatable(tab, {
__index = function(k, i)
return k.pairs[i[1]][i[2]];
end;
})

-- So you would be able to
tab.pairs[1][1] = 1
tab.pairs[1][2] = 2
print(tab[{1, 2}])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions