# HG changeset patch # User Kim Alvefur # Date 1579118881 -3600 # Node ID 9918b4b0cd588b8121e57fe5e9a0b1c1bf5937bc # Parent d78c5c9b0cf6ed3871f5bc445484f9c1f7131c31 util.array: Fix equality metamethod in Lua 5.3 Lua 5.2 only used the __eq metamethod if both operands have the same __eq, but Lua 5.3 will pick one from either operands that has one as long as both are tables. This results in array() == {} and all sorts of odd behavior, including array() == util.json.null. I think [array() == {}] should have the same semantics as {} == {} diff -r d78c5c9b0cf6 -r 9918b4b0cd58 util/array.lua --- a/util/array.lua Wed Jan 15 21:14:06 2020 +0100 +++ b/util/array.lua Wed Jan 15 21:08:01 2020 +0100 @@ -10,6 +10,7 @@ = 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 @@ 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