# HG changeset patch # User Matthew Wild # Date 1678818213 0 # Node ID bbae3acc669432890000a5a40c759a3c557f860a # Parent a7b7cdec2b3137bea364004d93aa94d67a142938 util.ip: Add is_ip() helper method to detect if an object is an ip object diff -r a7b7cdec2b31 -r bbae3acc6694 util/ip.lua --- 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; };