From 2a5ae358a2fbb0968e51efaf94ba4688dfc6de63 Mon Sep 17 00:00:00 2001 From: Marco Cirillo Date: Mon, 1 Apr 2013 22:34:44 +0000 Subject: modulemanager: add function to retrieve module items from a specific host entity. --- core/modulemanager.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'core/modulemanager.lua') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 35b9d0e5..48afe787 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -19,7 +19,7 @@ local prosody = prosody; local pcall, xpcall = pcall, xpcall; local setmetatable, rawget = setmetatable, rawget; -local pairs, type, tostring = pairs, type, tostring; +local pairs, type, tostring, t_insert = pairs, type, tostring, table.insert; local debug_traceback = debug.traceback; local unpack, select = unpack, select; @@ -278,6 +278,23 @@ function get_module(host, name) return modulemap[host] and modulemap[host][name]; end +function get_items(key, host) + local result = {}; + local modules = modulemap[host]; + if not key or not host or not modules then return nil; end + + for _, module in pairs(modules) do + local mod = module.module; + if mod.items and mod.items[key] then + for _, value in ipairs(mod.items[key]) do + t_insert(result, value); + end + end + end + + return result; +end + function get_modules(host) return modulemap[host]; end -- cgit v1.2.3 From bf1ce76f609162874ec87bd3dbbf81442bcd0be0 Mon Sep 17 00:00:00 2001 From: Marco Cirillo Date: Mon, 1 Apr 2013 23:41:57 +0000 Subject: modulemanager: add missing ipairs import. --- core/modulemanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core/modulemanager.lua') diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 48afe787..535c227b 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -19,7 +19,7 @@ local prosody = prosody; local pcall, xpcall = pcall, xpcall; local setmetatable, rawget = setmetatable, rawget; -local pairs, type, tostring, t_insert = pairs, type, tostring, table.insert; +local ipairs, pairs, type, tostring, t_insert = ipairs, pairs, type, tostring, table.insert; local debug_traceback = debug.traceback; local unpack, select = unpack, select; -- cgit v1.2.3