Changeset

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
parents 10592:9918b4b0cd58
children 10594:13d5fb74648f
files util/ip.lua
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
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",