From 4d0edf5ebdfe6f8dfd815526145e23b212449505 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 15 Jan 2020 21:16:08 +0100 Subject: util.ip: Fix equality metamethod for Lua 5.3 --- util/ip.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'util/ip.lua') diff --git a/util/ip.lua b/util/ip.lua index d1808225..d039e475 100644 --- a/util/ip.lua +++ b/util/ip.lua @@ -19,8 +19,14 @@ local ip_mt = { return ret; end, __tostring = function (ip) return ip.addr; end, - __eq = function (ipA, ipB) return ipA.packed == ipB.packed; end }; +ip_mt.__eq = function (ipA, ipB) + if getmetatable(ipA) ~= ip_mt or getmetatable(ipB) ~= ip_mt then + -- Lua 5.3+ calls this if both operands are tables, even if metatables differ + return false; + end + return ipA.packed == ipB.packed; +end local hex2bits = { ["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011", -- cgit v1.2.3