aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_util.lua
diff options
context:
space:
mode:
authorAndrew Lewis <nerf@judo.za.org>2018-03-08 15:16:24 +0200
committerAndrew Lewis <nerf@judo.za.org>2018-03-08 15:16:44 +0200
commit28f183d2bec2ff85949fd7dbcae1b7dd761fde8c (patch)
treed6d6804e0d6fe8a8e803abc1529cafdec8b92576 /lualib/lua_util.lua
parent4b9b8cc4c72dc6e7e3db8b7ffadbb13a4e4f8d3f (diff)
downloadrspamd-28f183d2bec2ff85949fd7dbcae1b7dd761fde8c.tar.gz
rspamd-28f183d2bec2ff85949fd7dbcae1b7dd761fde8c.zip
[Minor] Apply library functions in plugins
Diffstat (limited to 'lualib/lua_util.lua')
-rw-r--r--lualib/lua_util.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 88925aeec..d41d79fea 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -292,6 +292,35 @@ end
exports.check_experimental = check_experimental
--[[[
+-- @function lua_util.list_to_hash(list)
+-- Converts numerically-indexed table to table indexed by values
+-- @param {table} list numerically-indexed table or string, which is treated as a one-element list
+-- @return {table} table indexed by values
+-- @example
+-- local h = lua_util.list_to_hash({"a", "b"})
+-- -- h contains {a = true, b = true}
+--]]
+local function list_to_hash(list)
+ if type(list) == 'table' then
+ if list[1] then
+ local h = {}
+ for _, e in ipairs(list) do
+ h[e] = true
+ end
+ return h
+ else
+ return list
+ end
+ elseif type(list) == 'string' then
+ local h = {}
+ h[list] = true
+ return h
+ end
+end
+
+exports.list_to_hash = list_to_hash
+
+--[[[
-- @function lua_util.parse_time_interval(str)
-- Parses human readable time interval
-- Accepts 's' for seconds, 'm' for minutes, 'h' for hours, 'd' for days,