Mercurial > prosody-hg
diff util/ip.lua @ 12931:bbae3acc6694
util.ip: Add is_ip() helper method to detect if an object is an ip object
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 14 Mar 2023 18:23:33 +0000 |
| parents | a0ff5c438e9d |
| children | 9bb044705ea1 |
line wrap: on
line diff
--- a/util/ip.lua Sun Mar 12 13:05:50 2023 +0100 +++ b/util/ip.lua Tue Mar 14 18:23:33 2023 +0000 @@ -241,9 +241,14 @@ return ipA.bits:sub(1, bits) == ipB.bits:sub(1, bits); end +local function is_ip(obj) + return getmetatable(obj) == ip_mt; +end + return { new_ip = new_ip, commonPrefixLength = commonPrefixLength, parse_cidr = parse_cidr, match = match, + is_ip = is_ip; };
