Comparison

util/ip.lua @ 11200:bf8f2da84007

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Thu, 05 Nov 2020 22:31:25 +0100
parent 10593:079b31c8dbf2
child 11650:a227bc35771e
comparison
equal deleted inserted replaced
11199:6c7c50a4de32 11200:bf8f2da84007
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",