diff options
author | Matthew Wild <mwild1@gmail.com> | 2020-09-30 09:50:33 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2020-09-30 09:50:33 +0100 |
commit | 785c20f6ee7e61a5a91a8b6259623bc2a2bbffaa (patch) | |
tree | 3a37db7b805b1555d08cc61c7938cf512ff35ce0 /util/array.lua | |
parent | e55d037cdf89efac99c6144b381c9fa880f7fb93 (diff) | |
parent | b80ff2ae4f86aa26e055890a8284b55170ef2056 (diff) | |
download | prosody-785c20f6ee7e61a5a91a8b6259623bc2a2bbffaa.tar.gz prosody-785c20f6ee7e61a5a91a8b6259623bc2a2bbffaa.zip |
Merge 0.11->trunk
Diffstat (limited to 'util/array.lua')
-rw-r--r-- | util/array.lua | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/util/array.lua b/util/array.lua index 0b60a4fd..6e5c8383 100644 --- a/util/array.lua +++ b/util/array.lua @@ -10,6 +10,7 @@ local t_insert, t_sort, t_remove, t_concat = table.insert, table.sort, table.remove, table.concat; local setmetatable = setmetatable; +local getmetatable = getmetatable; local math_random = math.random; local math_floor = math.floor; local pairs, ipairs = pairs, ipairs; @@ -40,6 +41,10 @@ function array_mt.__add(a1, a2) end function array_mt.__eq(a, b) + if getmetatable(a) ~= array_mt or getmetatable(b) ~= array_mt then + -- Lua 5.3+ calls this if both operands are tables, even if metatables differ + return false; + end if #a == #b then for i = 1, #a do if a[i] ~= b[i] then @@ -129,9 +134,13 @@ function array_base.unique(outa, ina) end); end -function array_base.pluck(outa, ina, key) +function array_base.pluck(outa, ina, key, default) for i = 1, #ina do - outa[i] = ina[i][key]; + local v = ina[i][key]; + if v == nil then + v = default; + end + outa[i] = v; end return outa; end |