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 | 0bf98e614f8ce41994280fabf07738c5c22404bf (patch) | |
tree | 063139fdddc4b690d2a9be43b7b8d818efba2719 /util | |
parent | 911bea77466363a8bfcc01b1ebc689089d810efe (diff) | |
download | prosody-0bf98e614f8ce41994280fabf07738c5c22404bf.tar.gz prosody-0bf98e614f8ce41994280fabf07738c5c22404bf.zip |
util.array: Add O(n) equality check metamethod
Diffstat (limited to 'util')
-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 |