Skip to content

Instantly share code, notes, and snippets.

@amoeba
Created January 17, 2009 04:08
Show Gist options
  • Save amoeba/48256 to your computer and use it in GitHub Desktop.
Save amoeba/48256 to your computer and use it in GitHub Desktop.
Syntax hack to let you use the equals operator on two tables to check if table one is a member of table two
Set = {}
Set.mt = {}
function Set.new(t)
local set = {}
setmetatable(set, Set.mt)
for i,v in ipairs(t) do set[i] = v end
return set
end
Set.mt.__eq = function(a, b)
local l = (table.maxn(a) >= table.maxn(b)) and a or b
for _,v in ipairs(l) do
if a[1] == v then return true end
end
return false
end
if Set.new({"Rogue"}) == Set.new({"Rogue", "Shaman", "Warrior"}) then
print("true")
else
print("false")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment