aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorAsbjørn Sloth Tønnesen <ast@2e8.dk>2019-07-18 17:42:31 +0000
committerAsbjørn Sloth Tønnesen <ast@2e8.dk>2019-07-18 17:42:31 +0000
commite9d84b53e7c54f84da64967faf36c8b2791579f4 (patch)
tree077c6d41d59402a929aba22ba8510047a96205d5 /lua
parent54251356a23468136f6226134b0f8524a6ae3523 (diff)
downloadlua-inet-e9d84b53e7c54f84da64967faf36c8b2791579f4.tar.gz
lua-inet-e9d84b53e7c54f84da64967faf36c8b2791579f4.tar.xz
lua-inet-e9d84b53e7c54f84da64967faf36c8b2791579f4.zip
add inet.is_set()
Signed-off-by: Asbjørn Sloth Tønnesen <ast@2e8.dk>
Diffstat (limited to 'lua')
-rw-r--r--lua/inet/common.lua8
-rw-r--r--lua/inet/core.lua9
-rw-r--r--lua/inet/init.lua3
-rw-r--r--lua/inet/set.lua7
4 files changed, 21 insertions, 6 deletions
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