From e9d84b53e7c54f84da64967faf36c8b2791579f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Thu, 18 Jul 2019 17:42:31 +0000 Subject: add inet.is_set() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Asbjørn Sloth Tønnesen --- lua/inet/common.lua | 8 ++++++++ lua/inet/core.lua | 9 ++++----- lua/inet/init.lua | 3 ++- lua/inet/set.lua | 7 +++++++ 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 lua/inet/common.lua (limited to 'lua') diff --git a/lua/inet/common.lua b/lua/inet/common.lua new file mode 100644 index 0000000..6a84a13 --- /dev/null +++ b/lua/inet/common.lua @@ -0,0 +1,8 @@ +local M = {} + +function M.get_mt(t) + if type(t) ~= 'table' then return nil end + return getmetatable(t) +end + +return M diff --git a/lua/inet/core.lua b/lua/inet/core.lua index 4a5e14f..f9ff6e1 100644 --- a/lua/inet/core.lua +++ b/lua/inet/core.lua @@ -1,5 +1,7 @@ local bit32 = require 'bit32' +local common = require 'inet.common' + local format = string.format local lshift = bit32.lshift @@ -8,6 +10,8 @@ local band = bit32.band local replace = bit32.replace local bxor = bit32.bxor +local get_mt = common.get_mt + local mt2fam = {} local inet = {} @@ -21,11 +25,6 @@ local inet6 = setmetatable({}, inet) inet6.__index = inet6 mt2fam[inet6] = 6 -local function get_mt(t) - if type(t) ~= 'table' then return nil end - return getmetatable(t) -end - local function is_inet4(t) local mt = get_mt(t) return mt == inet4 diff --git a/lua/inet/init.lua b/lua/inet/init.lua index ea35f80..bea6ff2 100644 --- a/lua/inet/init.lua +++ b/lua/inet/init.lua @@ -14,6 +14,7 @@ M.is4 = core.is_inet4 M.is6 = core.is_inet6 M.is = core.is_inet -M.set = set.new +M.is_set = set.is_set +M.set = set.new return setmetatable(M, mt) diff --git a/lua/inet/set.lua b/lua/inet/set.lua index a353f30..a5d9056 100644 --- a/lua/inet/set.lua +++ b/lua/inet/set.lua @@ -1,6 +1,8 @@ local core = require 'inet.core' +local common = require 'inet.common' local is_inet = core.is_inet +local get_mt = common.get_mt local insert = table.insert local remove = table.remove @@ -197,4 +199,9 @@ end M.new = new_set +function M.is_set(t) + local mt = get_mt(t) + return mt == inet_set +end + return M -- cgit v1.2.1