Changeset

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 12930:a7b7cdec2b31
children 12932:9bb044705ea1
files util/ip.lua
diffstat 1 files changed, 5 insertions(+), 0 deletions(-) [+]
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;
 };