Diff

util/ip.lua @ 10593:079b31c8dbf2

util.ip: Fix equality metamethod for Lua 5.3
author Kim Alvefur <zash@zash.se>
date Wed, 15 Jan 2020 21:16:08 +0100
parent 9955:c74c89a96cbf
child 11650:a227bc35771e
line wrap: on
line diff
--- a/util/ip.lua	Wed Jan 15 21:08:01 2020 +0100
+++ b/util/ip.lua	Wed Jan 15 21:16:08 2020 +0100
@@ -19,8 +19,14 @@
 		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",