Mercurial > prosody-hg
comparison 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 |
| parents | c74c89a96cbf |
| children | a227bc35771e |
comparison
equal
deleted
inserted
replaced
| 10592:9918b4b0cd58 | 10593:079b31c8dbf2 |
|---|---|
| 17 local ret = method(ip); | 17 local ret = method(ip); |
| 18 ip[key] = ret; | 18 ip[key] = ret; |
| 19 return ret; | 19 return ret; |
| 20 end, | 20 end, |
| 21 __tostring = function (ip) return ip.addr; end, | 21 __tostring = function (ip) return ip.addr; end, |
| 22 __eq = function (ipA, ipB) return ipA.packed == ipB.packed; end | |
| 23 }; | 22 }; |
| 23 ip_mt.__eq = function (ipA, ipB) | |
| 24 if getmetatable(ipA) ~= ip_mt or getmetatable(ipB) ~= ip_mt then | |
| 25 -- Lua 5.3+ calls this if both operands are tables, even if metatables differ | |
| 26 return false; | |
| 27 end | |
| 28 return ipA.packed == ipB.packed; | |
| 29 end | |
| 24 | 30 |
| 25 local hex2bits = { | 31 local hex2bits = { |
| 26 ["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011", | 32 ["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011", |
| 27 ["4"] = "0100", ["5"] = "0101", ["6"] = "0110", ["7"] = "0111", | 33 ["4"] = "0100", ["5"] = "0101", ["6"] = "0110", ["7"] = "0111", |
| 28 ["8"] = "1000", ["9"] = "1001", ["A"] = "1010", ["B"] = "1011", | 34 ["8"] = "1000", ["9"] = "1001", ["A"] = "1010", ["B"] = "1011", |
