Software /
code /
prosody
Comparison
util/ip.lua @ 8382:e5d00bf4a4d5
util: Various minor changes to please [luacheck]
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 10 Nov 2017 05:42:32 +0100 |
parent | 7486:c415a3fd4485 |
child | 8428:ca44e462322c |
comparison
equal
deleted
inserted
replaced
8381:7f6184474149 | 8382:e5d00bf4a4d5 |
---|---|
7 | 7 |
8 local ip_methods = {}; | 8 local ip_methods = {}; |
9 local ip_mt = { __index = function (ip, key) return (ip_methods[key])(ip); end, | 9 local ip_mt = { __index = function (ip, key) return (ip_methods[key])(ip); end, |
10 __tostring = function (ip) return ip.addr; end, | 10 __tostring = function (ip) return ip.addr; end, |
11 __eq = function (ipA, ipB) return ipA.addr == ipB.addr; end}; | 11 __eq = function (ipA, ipB) return ipA.addr == ipB.addr; end}; |
12 local hex2bits = { ["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011", ["4"] = "0100", ["5"] = "0101", ["6"] = "0110", ["7"] = "0111", ["8"] = "1000", ["9"] = "1001", ["A"] = "1010", ["B"] = "1011", ["C"] = "1100", ["D"] = "1101", ["E"] = "1110", ["F"] = "1111" }; | 12 local hex2bits = { |
13 ["0"] = "0000", ["1"] = "0001", ["2"] = "0010", ["3"] = "0011", | |
14 ["4"] = "0100", ["5"] = "0101", ["6"] = "0110", ["7"] = "0111", | |
15 ["8"] = "1000", ["9"] = "1001", ["A"] = "1010", ["B"] = "1011", | |
16 ["C"] = "1100", ["D"] = "1101", ["E"] = "1110", ["F"] = "1111", | |
17 }; | |
13 | 18 |
14 local function new_ip(ipStr, proto) | 19 local function new_ip(ipStr, proto) |
15 if not proto then | 20 if not proto then |
16 local sep = ipStr:match("^%x+(.)"); | 21 local sep = ipStr:match("^%x+(.)"); |
17 if sep == ":" or (not(sep) and ipStr:sub(1,1) == ":") then | 22 if sep == ":" or (not(sep) and ipStr:sub(1,1) == ":") then |