Created
January 17, 2009 04:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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