Changeset

7976:2a7ef5fcaa77

util.array: Add O(n) equality check metamethod
author Kim Alvefur <zash@zash.se>
date Thu, 16 Mar 2017 19:09:57 +0100
parents 7975:c64ddee9d671
children 7977:01d6298de991
files util/array.lua
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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