Lua元表

local set1 = {1,2,3,7}
local set2 = {2,4,6,8}

local function union(self, another)
    local set = {}
    local result = {}

    for i, v in pairs(self) do set[v] = true end
    for j, v in pairs(another) do set[v] = true end

    for k, v in pairs(set) do table.insert(result, k) end

    return result
end

setmetatable(set1, {__add = union})

local set3 = set1 + set2

for _, v in ipairs(set3) do
    io.write(v.." ")
end