# HG changeset patch # User Kim Alvefur # Date 1489687797 -3600 # Node ID 2a7ef5fcaa77b515bd7570ba02fb75c65dd25f00 # Parent c64ddee9d67161f4b4f293aa87340772cd1b9d4b util.array: Add O(n) equality check metamethod diff -r c64ddee9d671 -r 2a7ef5fcaa77 util/array.lua --- a/util/array.lua Wed Mar 15 15:07:16 2017 +0100 +++ b/util/array.lua Thu Mar 16 19:09:57 2017 +0100 @@ -33,6 +33,19 @@ return res:append(a1):append(a2); end +function array_mt.__eq(a, b) + if #a == #b then + for i = 1, #a do + if a[i] ~= b[i] then + return false; + end + end + else + return false; + end + return true; +end + setmetatable(array, { __call = new_array }); -- Read-only methods