diff options
author | Kim Alvefur <zash@zash.se> | 2017-03-16 19:09:57 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2017-03-16 19:09:57 +0100 |
commit | 91262e2bc848551822a25cad697d6d660dd5301e (patch) | |
tree | 063139fdddc4b690d2a9be43b7b8d818efba2719 /util/array.lua | |
parent | 054f116c7dbe356666a312ab0ea19dfa03050999 (diff) | |
download | prosody-91262e2bc848551822a25cad697d6d660dd5301e.tar.gz prosody-91262e2bc848551822a25cad697d6d660dd5301e.zip |
util.array: Add O(n) equality check metamethod
Diffstat (limited to 'util/array.lua')
-rw-r--r-- | util/array.lua | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/util/array.lua b/util/array.lua index ea520f6b..05fa97ca 100644 --- a/util/array.lua +++ b/util/array.lua @@ -33,6 +33,19 @@ function array_mt.__add(a1, a2) 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 |