comparison util/set.lua @ 10594:13d5fb74648f

util.set: Fix equality metamethod in Lua 5.3
author Kim Alvefur <zash@zash.se>
date Wed, 15 Jan 2020 21:18:30 +0100
parents a96a2fbcc6c0
children 3bbb1af92514
comparison
equal deleted inserted replaced
10593:079b31c8dbf2 10594:13d5fb74648f
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8 8
9 local ipairs, pairs, setmetatable, next, tostring = 9 local ipairs, pairs, setmetatable, next, tostring =
10 ipairs, pairs, setmetatable, next, tostring; 10 ipairs, pairs, setmetatable, next, tostring;
11 local getmetatable = getmetatable;
11 local t_concat = table.concat; 12 local t_concat = table.concat;
12 13
13 local _ENV = nil; 14 local _ENV = nil;
14 -- luacheck: std none 15 -- luacheck: std none
15 16
144 end 145 end
145 end 146 end
146 return new_set; 147 return new_set;
147 end 148 end
148 function set_mt.__eq(set1, set2) 149 function set_mt.__eq(set1, set2)
150 if getmetatable(set1) ~= set_mt or getmetatable(set2) ~= set_mt then
151 -- Lua 5.3+ calls this if both operands are tables, even if metatables differ
152 return false;
153 end
154
149 set1, set2 = set1._items, set2._items; 155 set1, set2 = set1._items, set2._items;
150 for item in pairs(set1) do 156 for item in pairs(set1) do
151 if not set2[item] then 157 if not set2[item] then
152 return false; 158 return false;
153 end 159 end