Software /
code /
prosody
Annotate
core/moduleapi.lua @ 4534:7a0a31c4f6c5
modulemanager, moduleapi: Replace hooks multitable with an event_handlers map stored in individual modules. Also adds module:hook_object_event() to hook events on any util.events compatible object.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 22 Jan 2012 18:49:11 +0000 |
parent | 4531:c778ce7e3c78 |
child | 4538:d0a89c1c43fd |
rev | line source |
---|---|
4531
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- Prosody IM |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- Copyright (C) 2008-2012 Matthew Wild |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 -- Copyright (C) 2008-2012 Waqas Hussain |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 -- |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 -- COPYING file in the source package for more information. |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 -- |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local config = require "core.configmanager"; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local modulemanager = require "modulemanager"; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local array = require "util.array"; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local set = require "util.set"; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local logger = require "util.logger"; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local pluginloader = require "util.pluginloader"; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local multitable_new = require "util.multitable".new; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 local error, setmetatable, setfenv, type = error, setmetatable, setfenv, type; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local ipairs, pairs, select, unpack = ipairs, pairs, select, unpack; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 local tonumber, tostring = tonumber, tostring; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 local prosody = prosody; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 local hosts = prosody.hosts; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 -- Registry of shared module data |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 local shared_data = setmetatable({}, { __mode = "v" }); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 local NULL = {}; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 local api = {}; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 -- Returns the name of the current module |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 function api:get_name() |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 return self.name; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 -- Returns the host that the current module is serving |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 function api:get_host() |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 return self.host; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 function api:get_host_type() |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 return hosts[self.host].type; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 function api:set_global() |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 self.host = "*"; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 -- Update the logger |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 local _log = logger.init("mod_"..self.name); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 self.log = function (self, ...) return _log(...); end; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 self._log = _log; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 function api:add_feature(xmlns) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 self:add_item("feature", xmlns); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 function api:add_identity(category, type, name) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 self:add_item("identity", {category = category, type = type, name = name}); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 function api:add_extension(data) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 self:add_item("extension", data); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 function api:fire_event(...) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 return (hosts[self.host] or prosody).events.fire_event(...); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 |
4534
7a0a31c4f6c5
modulemanager, moduleapi: Replace hooks multitable with an event_handlers map stored in individual modules. Also adds module:hook_object_event() to hook events on any util.events compatible object.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
69 function api:hook_object_event(object, event, handler, priority) |
7a0a31c4f6c5
modulemanager, moduleapi: Replace hooks multitable with an event_handlers map stored in individual modules. Also adds module:hook_object_event() to hook events on any util.events compatible object.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
70 self.event_handlers[handler] = { name = event, priority = priority, object = object }; |
7a0a31c4f6c5
modulemanager, moduleapi: Replace hooks multitable with an event_handlers map stored in individual modules. Also adds module:hook_object_event() to hook events on any util.events compatible object.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
71 return object.add_handler(event, handler, priority); |
7a0a31c4f6c5
modulemanager, moduleapi: Replace hooks multitable with an event_handlers map stored in individual modules. Also adds module:hook_object_event() to hook events on any util.events compatible object.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
72 end |
7a0a31c4f6c5
modulemanager, moduleapi: Replace hooks multitable with an event_handlers map stored in individual modules. Also adds module:hook_object_event() to hook events on any util.events compatible object.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
73 |
4531
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 function api:hook(event, handler, priority) |
4534
7a0a31c4f6c5
modulemanager, moduleapi: Replace hooks multitable with an event_handlers map stored in individual modules. Also adds module:hook_object_event() to hook events on any util.events compatible object.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
75 return self:hook_object_event((hosts[self.host] or prosody).events, event, handler, priority); |
4531
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 function api:hook_global(event, handler, priority) |
4534
7a0a31c4f6c5
modulemanager, moduleapi: Replace hooks multitable with an event_handlers map stored in individual modules. Also adds module:hook_object_event() to hook events on any util.events compatible object.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
79 return self:hook_object_event(prosody.events, event, handler, priority); |
4531
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 function api:hook_stanza(xmlns, name, handler, priority) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 if not handler and type(name) == "function" then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 -- If only 2 options then they specified no xmlns |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 xmlns, name, handler, priority = nil, xmlns, name, handler; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 elseif not (handler and name) then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 self:log("warn", "Error: Insufficient parameters to module:hook_stanza()"); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 return; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 return self:hook("stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end, priority); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 function api:require(lib) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 local f, n = pluginloader.load_code(self.name, lib..".lib.lua"); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 if not f then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 f, n = pluginloader.load_code(lib, lib..".lib.lua"); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 if not f then error("Failed to load plugin library '"..lib.."', error: "..n); end -- FIXME better error message |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 setfenv(f, self.environment); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 return f(); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 function api:get_option(name, default_value) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 local value = config.get(self.host, self.name, name); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 if value == nil then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 value = config.get(self.host, "core", name); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 if value == nil then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 value = default_value; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 return value; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 function api:get_option_string(name, default_value) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 local value = self:get_option(name, default_value); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 if type(value) == "table" then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 if #value > 1 then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 self:log("error", "Config option '%s' does not take a list, using just the first item", name); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 value = value[1]; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 if value == nil then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 return nil; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 return tostring(value); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 function api:get_option_number(name, ...) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 local value = self:get_option(name, ...); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 if type(value) == "table" then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 if #value > 1 then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 self:log("error", "Config option '%s' does not take a list, using just the first item", name); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 value = value[1]; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 local ret = tonumber(value); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 if value ~= nil and ret == nil then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 self:log("error", "Config option '%s' not understood, expecting a number", name); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 return ret; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 function api:get_option_boolean(name, ...) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 local value = self:get_option(name, ...); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 if type(value) == "table" then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 if #value > 1 then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 self:log("error", "Config option '%s' does not take a list, using just the first item", name); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 value = value[1]; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 if value == nil then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 return nil; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 local ret = value == true or value == "true" or value == 1 or nil; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 if ret == nil then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 ret = (value == false or value == "false" or value == 0); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 if ret then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 ret = false; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 else |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 ret = nil; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 if ret == nil then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 self:log("error", "Config option '%s' not understood, expecting true/false", name); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 return ret; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 function api:get_option_array(name, ...) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 local value = self:get_option(name, ...); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 if value == nil then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 return nil; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 if type(value) ~= "table" then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 return array{ value }; -- Assume any non-list is a single-item list |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 return array():append(value); -- Clone |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 function api:get_option_set(name, ...) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 local value = self:get_option_array(name, ...); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 if value == nil then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
187 return nil; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
188 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
189 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
190 return set.new(value); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 local module_items = multitable_new(); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 function api:add_item(key, value) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 self.items = self.items or {}; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 self.items[key] = self.items[key] or {}; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 t_insert(self.items[key], value); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 self:fire_event("item-added/"..key, {source = self, item = value}); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
199 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 function api:remove_item(key, value) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
201 local t = self.items and self.items[key] or NULL; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
202 for i = #t,1,-1 do |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 if t[i] == value then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
204 t_remove(self.items[key], i); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
205 self:fire_event("item-removed/"..key, {source = self, item = value}); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 return value; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 function api:get_host_items(key) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 local result = {}; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 for mod_name, module in pairs(modulemanager.get_modules(self.host)) do |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 module = module.module; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 if module.items then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 for _, item in ipairs(module.items[key] or NULL) do |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 t_insert(result, item); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
218 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
219 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 for mod_name, module in pairs(modulemanager.get_modules("*")) do |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 module = module.module; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 if module.items then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 for _, item in ipairs(module.items[key] or NULL) do |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
225 t_insert(result, item); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
226 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
227 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
228 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
229 return result; |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
230 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
231 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 function api:handle_items(type, added_cb, removed_cb, existing) |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
233 self:hook("item-added/"..type, added_cb); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 self:hook("item-removed/"..type, removed_cb); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 if existing ~= false then |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 for _, item in ipairs(self:get_host_items(type)) do |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
237 added_cb({ item = item }); |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
238 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
239 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
240 end |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
241 |
c778ce7e3c78
modulemanager: Move in-module API functions to core.moduleapi (half the file size, yay)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
242 return api; |