Software / code / prosody
Annotate
core/modulemanager.lua @ 13832:5973a5d22ab5 13.0
mod_storage_sql: Delay showing SQL library error until attempted load
This should ensure that e.g. failure to load LuaSQLite3 is not logged
unless it is needed, since module failures are very verbose.
Closes #1919
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 07 Apr 2025 20:23:00 +0200 |
| parent | 13829:dde0ce03049b |
| rev | line source |
|---|---|
|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1505
diff
changeset
|
1 -- Prosody IM |
|
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2828
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
|
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2828
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5411
diff
changeset
|
4 -- |
| 758 | 5 -- This project is MIT/X11 licensed. Please see the |
| 6 -- COPYING file in the source package for more information. | |
|
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
467
diff
changeset
|
7 -- |
|
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
467
diff
changeset
|
8 |
|
12972
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12450
diff
changeset
|
9 local array = require "prosody.util.array"; |
|
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12450
diff
changeset
|
10 local logger = require "prosody.util.logger"; |
|
540
ec03f6968fa8
Added function add_feature to modules API (for adding disco features)
Waqas Hussain <waqas20@gmail.com>
parents:
519
diff
changeset
|
11 local log = logger.init("modulemanager"); |
|
12972
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12450
diff
changeset
|
12 local config = require "prosody.core.configmanager"; |
|
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12450
diff
changeset
|
13 local pluginloader = require "prosody.util.pluginloader"; |
|
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12450
diff
changeset
|
14 local envload = require "prosody.util.envload"; |
|
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12450
diff
changeset
|
15 local set = require "prosody.util.set"; |
|
4896
27cda15104f2
modulemanager, moduleapi: Turn module.event_handlers into a multitable and track object->event->handler associations correctly (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
4893
diff
changeset
|
16 |
|
12972
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12450
diff
changeset
|
17 local core_features = require "prosody.core.features".available; |
|
12254
5b0c8e499288
modulemanager: Add plugin load filter that reads module metadata from source
Matthew Wild <mwild1@gmail.com>
parents:
12253
diff
changeset
|
18 |
|
12972
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12450
diff
changeset
|
19 local new_multitable = require "prosody.util.multitable".new; |
|
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12450
diff
changeset
|
20 local api = require "prosody.core.moduleapi"; -- Module API container |
| 30 | 21 |
|
1247
4721e4124692
modulemanager: module:hook now allows global modules to hook events on the prosody.events object
Waqas Hussain <waqas20@gmail.com>
parents:
1231
diff
changeset
|
22 local prosody = prosody; |
|
8717
9ddd0fbbe53a
core: Use prosody.hosts instead of _G.hosts for consistency
Kim Alvefur <zash@zash.se>
parents:
8555
diff
changeset
|
23 local hosts = prosody.hosts; |
|
747
40837f3422ab
modulemanager: Add get_host_type() API method, and fix up call_module_method to work properly
Matthew Wild <mwild1@gmail.com>
parents:
746
diff
changeset
|
24 |
|
12972
ead41e25ebc0
core: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12450
diff
changeset
|
25 local xpcall = require "prosody.util.xpcall".xpcall; |
|
9563
732314eb3258
modulemanager: Fix issues introduced in previous commit acf74ad0b795 [thanks luacheck, scansion]
Matthew Wild <mwild1@gmail.com>
parents:
9562
diff
changeset
|
26 local debug_traceback = debug.traceback; |
|
5021
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4896
diff
changeset
|
27 local setmetatable, rawget = setmetatable, rawget; |
|
9563
732314eb3258
modulemanager: Fix issues introduced in previous commit acf74ad0b795 [thanks luacheck, scansion]
Matthew Wild <mwild1@gmail.com>
parents:
9562
diff
changeset
|
28 local ipairs, pairs, type, t_insert = ipairs, pairs, type, table.insert; |
|
13614
601ec2c19180
modulemanager: Handle multiple digits in Lua version number
Matthew Wild <mwild1@gmail.com>
parents:
13361
diff
changeset
|
29 local lua_version = _VERSION:match("5%.%d+$"); |
|
2977
686f9a5a7f5e
modulemanager: Log proper tracebacks on errors during module load/unload.
Waqas Hussain <waqas20@gmail.com>
parents:
2951
diff
changeset
|
30 |
|
10288
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
31 local autoload_modules = { |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
32 "presence", |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
33 "message", |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
34 "iq", |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
35 "offline", |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
36 "c2s", |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
37 "s2s", |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
38 "s2s_auth_certs", |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
39 }; |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
40 local component_inheritable_modules = { |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
41 "tls", |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
42 "saslauth", |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
43 "dialback", |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
44 "iq", |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
45 "s2s", |
|
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
46 "s2s_bidi", |
|
12079
76a5c0261793
core.modulemanager: Load mod_smacks on Components
Kim Alvefur <zash@zash.se>
parents:
11585
diff
changeset
|
47 "smacks", |
|
11585
057ce005937e
core.modulemanager: Inherit mod_server_contact_info onto components #1270
Kim Alvefur <zash@zash.se>
parents:
11287
diff
changeset
|
48 "server_contact_info", |
|
10288
f36f7d2c269b
core.modulemanager: Split lists across multiple lines for improved readability
Kim Alvefur <zash@zash.se>
parents:
10250
diff
changeset
|
49 }; |
|
1505
e19cb945c25b
modulemanager: Small code improvement, move autoloaded modules list to the top of the file
Matthew Wild <mwild1@gmail.com>
parents:
1504
diff
changeset
|
50 |
|
467
66f145f5c932
Update Makefile to now pass config paths to prosody. Update prosody, modulemanager and connectionlisteners to obey these paths.
Matthew Wild <mwild1@gmail.com>
parents:
439
diff
changeset
|
51 -- We need this to let modules access the real global namespace |
| 30 | 52 local _G = _G; |
| 53 | |
|
6779
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6661
diff
changeset
|
54 local _ENV = nil; |
|
8555
4f0f5b49bb03
vairious: Add annotation when an empty environment is set [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7947
diff
changeset
|
55 -- luacheck: std none |
| 30 | 56 |
|
13829
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
57 local function plugin_load_filter_cb(path, content) |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
58 local metadata = {}; |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
59 for line in content:gmatch("([^\r\n]+)\r?\n") do |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
60 local key, value = line:match("^%-%-%% *([%w_]+): *(.+)$"); |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
61 if key then |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
62 value = value:gsub("%s+$", ""); |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
63 metadata[key] = value; |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
64 end |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
65 end |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
66 |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
67 if metadata.lua then |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
68 local supported = false; |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
69 for supported_lua_version in metadata.lua:gmatch("[^, ]+") do |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
70 if supported_lua_version == lua_version then |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
71 supported = true; |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
72 break; |
|
12254
5b0c8e499288
modulemanager: Add plugin load filter that reads module metadata from source
Matthew Wild <mwild1@gmail.com>
parents:
12253
diff
changeset
|
73 end |
|
5b0c8e499288
modulemanager: Add plugin load filter that reads module metadata from source
Matthew Wild <mwild1@gmail.com>
parents:
12253
diff
changeset
|
74 end |
|
13829
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
75 if not supported then |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
76 if prosody.process_type ~= "prosodyctl" then |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
77 log("warn", "Not loading module, we have Lua %s but the module requires one of (%s): %s", lua_version, metadata.lua, path); |
|
13615
b03b5716e4cf
modulemanager: Allow modules to specify supported Lua versions in metadata
Matthew Wild <mwild1@gmail.com>
parents:
13614
diff
changeset
|
78 end |
|
13829
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
79 return nil, "incompatible with Lua "..lua_version; -- Don't load this module |
|
13615
b03b5716e4cf
modulemanager: Allow modules to specify supported Lua versions in metadata
Matthew Wild <mwild1@gmail.com>
parents:
13614
diff
changeset
|
80 end |
|
13829
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
81 end |
|
13615
b03b5716e4cf
modulemanager: Allow modules to specify supported Lua versions in metadata
Matthew Wild <mwild1@gmail.com>
parents:
13614
diff
changeset
|
82 |
|
13829
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
83 if metadata.conflicts then |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
84 local conflicts_features = set.new(array.collect(metadata.conflicts:gmatch("[^, ]+"))); |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
85 local conflicted_features = set.intersection(conflicts_features, core_features); |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
86 if not conflicted_features:empty() then |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
87 if prosody.process_type ~= "prosodyctl" then |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
88 log("warn", "Not loading module, due to conflict with built-in features '%s': %s", conflicted_features, path); |
|
12254
5b0c8e499288
modulemanager: Add plugin load filter that reads module metadata from source
Matthew Wild <mwild1@gmail.com>
parents:
12253
diff
changeset
|
89 end |
|
13829
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
90 return nil, "conflict with built-in feature"; -- Don't load this module |
|
12254
5b0c8e499288
modulemanager: Add plugin load filter that reads module metadata from source
Matthew Wild <mwild1@gmail.com>
parents:
12253
diff
changeset
|
91 end |
|
13829
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
92 end |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
93 if metadata.requires then |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
94 local required_features = set.new(array.collect(metadata.requires:gmatch("[^, ]+"))); |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
95 local missing_features = required_features - core_features; |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
96 if not missing_features:empty() then |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
97 if prosody.process_type ~= "prosodyctl" then |
|
12254
5b0c8e499288
modulemanager: Add plugin load filter that reads module metadata from source
Matthew Wild <mwild1@gmail.com>
parents:
12253
diff
changeset
|
98 log("warn", "Not loading module, due to missing features '%s': %s", missing_features, path); |
|
5b0c8e499288
modulemanager: Add plugin load filter that reads module metadata from source
Matthew Wild <mwild1@gmail.com>
parents:
12253
diff
changeset
|
99 end |
|
13829
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
100 return nil, "Prosody version missing required feature"; -- Don't load this module |
|
12254
5b0c8e499288
modulemanager: Add plugin load filter that reads module metadata from source
Matthew Wild <mwild1@gmail.com>
parents:
12253
diff
changeset
|
101 end |
|
13829
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
102 end |
|
12254
5b0c8e499288
modulemanager: Add plugin load filter that reads module metadata from source
Matthew Wild <mwild1@gmail.com>
parents:
12253
diff
changeset
|
103 |
|
13829
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
104 return path, content, metadata; |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
105 end; |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
106 |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
107 local loader = pluginloader.init({ |
|
dde0ce03049b
modulemanager, util.pluginloader: Improve error message when load fails but some candidates were filtered
Matthew Wild <mwild1@gmail.com>
parents:
13689
diff
changeset
|
108 load_filter_cb = plugin_load_filter_cb; |
|
12253
57d35fcde488
modulemanager, moduleapi: Switch to new pluginloader interface
Matthew Wild <mwild1@gmail.com>
parents:
12146
diff
changeset
|
109 }); |
|
57d35fcde488
modulemanager, moduleapi: Switch to new pluginloader interface
Matthew Wild <mwild1@gmail.com>
parents:
12146
diff
changeset
|
110 |
|
7947
24170d74b00b
core: Split some very long lines [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7303
diff
changeset
|
111 local load_modules_for_host, load, unload, reload, get_module, get_items; |
|
24170d74b00b
core: Split some very long lines [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7303
diff
changeset
|
112 local get_modules, is_loaded, module_has_method, call_module_method; |
|
438
193f9dd64f17
Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents:
400
diff
changeset
|
113 |
|
4535
d46e9ad4fe8a
modulemanager: Cleanup some unused variables, imports, whitespace and add a comment.
Matthew Wild <mwild1@gmail.com>
parents:
4534
diff
changeset
|
114 -- [host] = { [module] = module_env } |
|
584
eb0cea29c8d7
Temporary hack for global modules
Matthew Wild <mwild1@gmail.com>
parents:
579
diff
changeset
|
115 local modulemap = { ["*"] = {} }; |
|
438
193f9dd64f17
Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents:
400
diff
changeset
|
116 |
|
8916
e727747279a0
modulemanager: Expose function to get the list of modules that should be loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
8717
diff
changeset
|
117 -- Get the list of modules to be loaded on a host |
|
e727747279a0
modulemanager: Expose function to get the list of modules that should be loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
8717
diff
changeset
|
118 local function get_modules_for_host(host) |
|
5377
898454038524
core.*: Complete removal of all traces of the "core" section and section-related code.
Kim Alvefur <zash@zash.se>
parents:
5192
diff
changeset
|
119 local component = config.get(host, "component_module"); |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5411
diff
changeset
|
120 |
|
5377
898454038524
core.*: Complete removal of all traces of the "core" section and section-related code.
Kim Alvefur <zash@zash.se>
parents:
5192
diff
changeset
|
121 local global_modules_enabled = config.get("*", "modules_enabled"); |
|
898454038524
core.*: Complete removal of all traces of the "core" section and section-related code.
Kim Alvefur <zash@zash.se>
parents:
5192
diff
changeset
|
122 local global_modules_disabled = config.get("*", "modules_disabled"); |
|
898454038524
core.*: Complete removal of all traces of the "core" section and section-related code.
Kim Alvefur <zash@zash.se>
parents:
5192
diff
changeset
|
123 local host_modules_enabled = config.get(host, "modules_enabled"); |
|
898454038524
core.*: Complete removal of all traces of the "core" section and section-related code.
Kim Alvefur <zash@zash.se>
parents:
5192
diff
changeset
|
124 local host_modules_disabled = config.get(host, "modules_disabled"); |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5411
diff
changeset
|
125 |
|
3595
ec1151d0c4a4
modulemanager: load_modules_for_host(): Inherit 'tls' and 'dialback' from global modules list for components, and load the component module. Also refactored to use util.set.
Waqas Hussain <waqas20@gmail.com>
parents:
3588
diff
changeset
|
126 if host_modules_enabled == global_modules_enabled then host_modules_enabled = nil; end |
|
ec1151d0c4a4
modulemanager: load_modules_for_host(): Inherit 'tls' and 'dialback' from global modules list for components, and load the component module. Also refactored to use util.set.
Waqas Hussain <waqas20@gmail.com>
parents:
3588
diff
changeset
|
127 if host_modules_disabled == global_modules_disabled then host_modules_disabled = nil; end |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5411
diff
changeset
|
128 |
|
3595
ec1151d0c4a4
modulemanager: load_modules_for_host(): Inherit 'tls' and 'dialback' from global modules list for components, and load the component module. Also refactored to use util.set.
Waqas Hussain <waqas20@gmail.com>
parents:
3588
diff
changeset
|
129 local global_modules = set.new(autoload_modules) + set.new(global_modules_enabled) - set.new(global_modules_disabled); |
|
ec1151d0c4a4
modulemanager: load_modules_for_host(): Inherit 'tls' and 'dialback' from global modules list for components, and load the component module. Also refactored to use util.set.
Waqas Hussain <waqas20@gmail.com>
parents:
3588
diff
changeset
|
130 if component then |
|
3596
bbeba9f2acf8
modulemanager: load_modules_for_host(): For components, the inherited modules are the intersection of the inheritable and global modules lists, not the difference.
Waqas Hussain <waqas20@gmail.com>
parents:
3595
diff
changeset
|
131 global_modules = set.intersection(set.new(component_inheritable_modules), global_modules); |
|
1960
1e674dae31ae
modulemanager: Re-organise module loading to still work when no global modules_enabled is defined in the config (thanks hoelzro for accidentally discovering this one)
Matthew Wild <mwild1@gmail.com>
parents:
1946
diff
changeset
|
132 end |
|
4135
9dfb3c0101b5
modulemanager: Fix disabling a module on a single host
Paul Aurich <paul@darkrain42.org>
parents:
4002
diff
changeset
|
133 local modules = (global_modules + set.new(host_modules_enabled)) - set.new(host_modules_disabled); |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5411
diff
changeset
|
134 |
|
10433
7777f25d5266
core.modulemanager: Disable mod_vcard if mod_vcard_legacy is enabled to prevent conflict (#1469)
Kim Alvefur <zash@zash.se>
parents:
9563
diff
changeset
|
135 if modules:contains("vcard") and modules:contains("vcard_legacy") then |
|
7777f25d5266
core.modulemanager: Disable mod_vcard if mod_vcard_legacy is enabled to prevent conflict (#1469)
Kim Alvefur <zash@zash.se>
parents:
9563
diff
changeset
|
136 log("error", "The mod_vcard_legacy plugin replaces mod_vcard but both are enabled. Please update your config."); |
|
7777f25d5266
core.modulemanager: Disable mod_vcard if mod_vcard_legacy is enabled to prevent conflict (#1469)
Kim Alvefur <zash@zash.se>
parents:
9563
diff
changeset
|
137 modules:remove("vcard"); |
|
7777f25d5266
core.modulemanager: Disable mod_vcard if mod_vcard_legacy is enabled to prevent conflict (#1469)
Kim Alvefur <zash@zash.se>
parents:
9563
diff
changeset
|
138 end |
|
7777f25d5266
core.modulemanager: Disable mod_vcard if mod_vcard_legacy is enabled to prevent conflict (#1469)
Kim Alvefur <zash@zash.se>
parents:
9563
diff
changeset
|
139 |
|
8916
e727747279a0
modulemanager: Expose function to get the list of modules that should be loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
8717
diff
changeset
|
140 return modules, component; |
|
e727747279a0
modulemanager: Expose function to get the list of modules that should be loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
8717
diff
changeset
|
141 end |
|
e727747279a0
modulemanager: Expose function to get the list of modules that should be loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
8717
diff
changeset
|
142 |
|
e727747279a0
modulemanager: Expose function to get the list of modules that should be loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
8717
diff
changeset
|
143 -- Load modules when a host is activated |
|
e727747279a0
modulemanager: Expose function to get the list of modules that should be loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
8717
diff
changeset
|
144 function load_modules_for_host(host) |
|
e727747279a0
modulemanager: Expose function to get the list of modules that should be loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
8717
diff
changeset
|
145 local modules, component_module = get_modules_for_host(host); |
|
e727747279a0
modulemanager: Expose function to get the list of modules that should be loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
8717
diff
changeset
|
146 |
|
e727747279a0
modulemanager: Expose function to get the list of modules that should be loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
8717
diff
changeset
|
147 -- Ensure component module is loaded first |
|
e727747279a0
modulemanager: Expose function to get the list of modules that should be loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
8717
diff
changeset
|
148 if component_module then |
|
e727747279a0
modulemanager: Expose function to get the list of modules that should be loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
8717
diff
changeset
|
149 load(host, component_module); |
|
637
30b8ad9f7b70
Fix for not loading global modules when host-specific modules are specified in config
Matthew Wild <mwild1@gmail.com>
parents:
615
diff
changeset
|
150 end |
|
3595
ec1151d0c4a4
modulemanager: load_modules_for_host(): Inherit 'tls' and 'dialback' from global modules list for components, and load the component module. Also refactored to use util.set.
Waqas Hussain <waqas20@gmail.com>
parents:
3588
diff
changeset
|
151 for module in modules do |
|
ec1151d0c4a4
modulemanager: load_modules_for_host(): Inherit 'tls' and 'dialback' from global modules list for components, and load the component module. Also refactored to use util.set.
Waqas Hussain <waqas20@gmail.com>
parents:
3588
diff
changeset
|
152 load(host, module); |
|
573
f6555ebf84ec
Move module loading to modulemanager
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
153 end |
|
f6555ebf84ec
Move module loading to modulemanager
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
154 end |
|
4533
c6480d17be1e
modulemanager: Drop unnecessary prosody_events local
Matthew Wild <mwild1@gmail.com>
parents:
4532
diff
changeset
|
155 prosody.events.add_handler("host-activated", load_modules_for_host); |
|
4733
791388f90156
modulemanager: Clear modulemap when a host is deactivated (thanks xnyhps)
Matthew Wild <mwild1@gmail.com>
parents:
4728
diff
changeset
|
156 prosody.events.add_handler("host-deactivated", function (host) |
|
791388f90156
modulemanager: Clear modulemap when a host is deactivated (thanks xnyhps)
Matthew Wild <mwild1@gmail.com>
parents:
4728
diff
changeset
|
157 modulemap[host] = nil; |
|
791388f90156
modulemanager: Clear modulemap when a host is deactivated (thanks xnyhps)
Matthew Wild <mwild1@gmail.com>
parents:
4728
diff
changeset
|
158 end); |
| 30 | 159 |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
160 --- Private helpers --- |
|
438
193f9dd64f17
Bumper commit for the new modulemanager API \o/ Updates all the modules, though some more changes may be in store.
Matthew Wild <mwild1@gmail.com>
parents:
400
diff
changeset
|
161 |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
162 local function do_unload_module(host, name) |
|
2278
8c10f13c0c20
modulemanager, net.dns: Remove trailing whitespace
Matthew Wild <mwild1@gmail.com>
parents:
2270
diff
changeset
|
163 local mod = get_module(host, name); |
|
439
6608ad3a72f3
is_loaded() and incomplete unload() for modules
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
164 if not mod then return nil, "module-not-loaded"; end |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5411
diff
changeset
|
165 |
|
745
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
166 if module_has_method(mod, "unload") then |
|
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
167 local ok, err = call_module_method(mod, "unload"); |
|
439
6608ad3a72f3
is_loaded() and incomplete unload() for modules
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
168 if (not ok) and err then |
|
745
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
169 log("warn", "Non-fatal error unloading module '%s' on '%s': %s", name, host, err); |
|
439
6608ad3a72f3
is_loaded() and incomplete unload() for modules
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
170 end |
|
674
4f506c627b49
modulemanager: module.unload now gets called when modules are being unloaded
Waqas Hussain <waqas20@gmail.com>
parents:
670
diff
changeset
|
171 end |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5411
diff
changeset
|
172 |
|
4896
27cda15104f2
modulemanager, moduleapi: Turn module.event_handlers into a multitable and track object->event->handler associations correctly (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
4893
diff
changeset
|
173 for object, event, handler in mod.module.event_handlers:iter(nil, nil, nil) do |
|
27cda15104f2
modulemanager, moduleapi: Turn module.event_handlers into a multitable and track object->event->handler associations correctly (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
4893
diff
changeset
|
174 object.remove_handler(event, handler); |
|
1259
6bd11bca9725
modulemanager: Keep track of event handlers added by module:hook, and remove them on module unload
Waqas Hussain <waqas20@gmail.com>
parents:
1253
diff
changeset
|
175 end |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5411
diff
changeset
|
176 |
|
2828
fbddc3ed0d09
modulemanager: Fire item-removed events on module unload.
Waqas Hussain <waqas20@gmail.com>
parents:
2072
diff
changeset
|
177 if mod.module.items then -- remove items |
|
4604
eef5e3a83792
modulemanager: Use appropriate events object for global modules when firing item-removed on unload
Matthew Wild <mwild1@gmail.com>
parents:
4565
diff
changeset
|
178 local events = (host == "*" and prosody.events) or hosts[host].events; |
|
2828
fbddc3ed0d09
modulemanager: Fire item-removed events on module unload.
Waqas Hussain <waqas20@gmail.com>
parents:
2072
diff
changeset
|
179 for key,t in pairs(mod.module.items) do |
|
fbddc3ed0d09
modulemanager: Fire item-removed events on module unload.
Waqas Hussain <waqas20@gmail.com>
parents:
2072
diff
changeset
|
180 for i = #t,1,-1 do |
|
fbddc3ed0d09
modulemanager: Fire item-removed events on module unload.
Waqas Hussain <waqas20@gmail.com>
parents:
2072
diff
changeset
|
181 local value = t[i]; |
|
fbddc3ed0d09
modulemanager: Fire item-removed events on module unload.
Waqas Hussain <waqas20@gmail.com>
parents:
2072
diff
changeset
|
182 t[i] = nil; |
|
4604
eef5e3a83792
modulemanager: Use appropriate events object for global modules when firing item-removed on unload
Matthew Wild <mwild1@gmail.com>
parents:
4565
diff
changeset
|
183 events.fire_event("item-removed/"..key, {source = mod.module, item = value}); |
|
2828
fbddc3ed0d09
modulemanager: Fire item-removed events on module unload.
Waqas Hussain <waqas20@gmail.com>
parents:
2072
diff
changeset
|
184 end |
|
fbddc3ed0d09
modulemanager: Fire item-removed events on module unload.
Waqas Hussain <waqas20@gmail.com>
parents:
2072
diff
changeset
|
185 end |
|
fbddc3ed0d09
modulemanager: Fire item-removed events on module unload.
Waqas Hussain <waqas20@gmail.com>
parents:
2072
diff
changeset
|
186 end |
|
4665
6be91ca54613
modulemanager: Set module.loaded = false on unload
Matthew Wild <mwild1@gmail.com>
parents:
4662
diff
changeset
|
187 mod.module.loaded = false; |
|
1986
d4ba9d94eb74
modulemanager: Slightly rearranged code for more robust unloading of modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1960
diff
changeset
|
188 modulemap[host][name] = nil; |
|
670
d5cf10b7fc44
Modulemanager: Basic modules can now be unloaded correctly
Waqas Hussain <waqas20@gmail.com>
parents:
637
diff
changeset
|
189 return true; |
|
439
6608ad3a72f3
is_loaded() and incomplete unload() for modules
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
190 end |
|
6608ad3a72f3
is_loaded() and incomplete unload() for modules
Matthew Wild <mwild1@gmail.com>
parents:
438
diff
changeset
|
191 |
|
5192
3fc3a3072cc2
modulemanager: Set module.reloading when a module is reloading, and when loading make the saved state available in module.saved_state (if any)
Matthew Wild <mwild1@gmail.com>
parents:
5123
diff
changeset
|
192 local function do_load_module(host, module_name, state) |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
193 if not (host and module_name) then |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
194 return nil, "insufficient-parameters"; |
|
4638
352cd61e2682
modulemanager: Allow loading a module onto "*" (part-fixes #228)
Matthew Wild <mwild1@gmail.com>
parents:
4606
diff
changeset
|
195 elseif not hosts[host] and host ~= "*"then |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
196 return nil, "unknown-host"; |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
197 end |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5411
diff
changeset
|
198 |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
199 if not modulemap[host] then |
|
5123
7c5c86fa552e
hostmanager, modulemanager: Ensure hosts[*].modules always exists.
Waqas Hussain <waqas20@gmail.com>
parents:
5021
diff
changeset
|
200 modulemap[host] = hosts[host].modules; |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
201 end |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5411
diff
changeset
|
202 |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
203 if modulemap[host][module_name] then |
|
7303
439d00063620
modulemanager: Silence log message about attempts to load already loaded modules for shared modules
Kim Alvefur <zash@zash.se>
parents:
7163
diff
changeset
|
204 if not modulemap["*"][module_name] then |
|
439d00063620
modulemanager: Silence log message about attempts to load already loaded modules for shared modules
Kim Alvefur <zash@zash.se>
parents:
7163
diff
changeset
|
205 log("debug", "%s is already loaded for %s, so not loading again", module_name, host); |
|
439d00063620
modulemanager: Silence log message about attempts to load already loaded modules for shared modules
Kim Alvefur <zash@zash.se>
parents:
7163
diff
changeset
|
206 end |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
207 return nil, "module-already-loaded"; |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
208 elseif modulemap["*"][module_name] then |
|
4642
c1602c07d14d
modulemanager: Support for shared modules - function module.add_host(host_module) in a global module
Matthew Wild <mwild1@gmail.com>
parents:
4641
diff
changeset
|
209 local mod = modulemap["*"][module_name]; |
|
c1602c07d14d
modulemanager: Support for shared modules - function module.add_host(host_module) in a global module
Matthew Wild <mwild1@gmail.com>
parents:
4641
diff
changeset
|
210 if module_has_method(mod, "add_host") then |
|
c1602c07d14d
modulemanager: Support for shared modules - function module.add_host(host_module) in a global module
Matthew Wild <mwild1@gmail.com>
parents:
4641
diff
changeset
|
211 local _log = logger.init(host..":"..module_name); |
|
c1602c07d14d
modulemanager: Support for shared modules - function module.add_host(host_module) in a global module
Matthew Wild <mwild1@gmail.com>
parents:
4641
diff
changeset
|
212 local host_module_api = setmetatable({ |
|
12450
7efd4bcaa95c
core.modulemanager: Fix global flag on per-host instances of shared modules (fix #1736)
Kim Alvefur <zash@zash.se>
parents:
12275
diff
changeset
|
213 global = false, |
|
4896
27cda15104f2
modulemanager, moduleapi: Turn module.event_handlers into a multitable and track object->event->handler associations correctly (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
4893
diff
changeset
|
214 host = host, event_handlers = new_multitable(), items = {}; |
|
6661
90e846e8a788
modulemanager: Add luacheck annotations
Matthew Wild <mwild1@gmail.com>
parents:
6660
diff
changeset
|
215 _log = _log, log = function (self, ...) return _log(...); end; --luacheck: ignore 212/self |
|
4642
c1602c07d14d
modulemanager: Support for shared modules - function module.add_host(host_module) in a global module
Matthew Wild <mwild1@gmail.com>
parents:
4641
diff
changeset
|
216 },{ |
|
c1602c07d14d
modulemanager: Support for shared modules - function module.add_host(host_module) in a global module
Matthew Wild <mwild1@gmail.com>
parents:
4641
diff
changeset
|
217 __index = modulemap["*"][module_name].module; |
|
c1602c07d14d
modulemanager: Support for shared modules - function module.add_host(host_module) in a global module
Matthew Wild <mwild1@gmail.com>
parents:
4641
diff
changeset
|
218 }); |
|
4728
7c81b04a4fed
modulemanager: Set module.environment before calling add_host, otherwise the module will get the parent's environment (thanks xnyhps and Maranda)
Matthew Wild <mwild1@gmail.com>
parents:
4665
diff
changeset
|
219 local host_module = setmetatable({ module = host_module_api }, { __index = mod }); |
|
7c81b04a4fed
modulemanager: Set module.environment before calling add_host, otherwise the module will get the parent's environment (thanks xnyhps and Maranda)
Matthew Wild <mwild1@gmail.com>
parents:
4665
diff
changeset
|
220 host_module_api.environment = host_module; |
|
4776
dbe9d75c0452
modulemanager: Fixes to handle circular dependencies in module:depends()
Matthew Wild <mwild1@gmail.com>
parents:
4746
diff
changeset
|
221 modulemap[host][module_name] = host_module; |
|
4642
c1602c07d14d
modulemanager: Support for shared modules - function module.add_host(host_module) in a global module
Matthew Wild <mwild1@gmail.com>
parents:
4641
diff
changeset
|
222 local ok, result, module_err = call_module_method(mod, "add_host", host_module_api); |
|
4776
dbe9d75c0452
modulemanager: Fixes to handle circular dependencies in module:depends()
Matthew Wild <mwild1@gmail.com>
parents:
4746
diff
changeset
|
223 if not ok or result == false then |
|
dbe9d75c0452
modulemanager: Fixes to handle circular dependencies in module:depends()
Matthew Wild <mwild1@gmail.com>
parents:
4746
diff
changeset
|
224 modulemap[host][module_name] = nil; |
|
dbe9d75c0452
modulemanager: Fixes to handle circular dependencies in module:depends()
Matthew Wild <mwild1@gmail.com>
parents:
4746
diff
changeset
|
225 return nil, ok and module_err or result; |
|
dbe9d75c0452
modulemanager: Fixes to handle circular dependencies in module:depends()
Matthew Wild <mwild1@gmail.com>
parents:
4746
diff
changeset
|
226 end |
|
4642
c1602c07d14d
modulemanager: Support for shared modules - function module.add_host(host_module) in a global module
Matthew Wild <mwild1@gmail.com>
parents:
4641
diff
changeset
|
227 return host_module; |
|
c1602c07d14d
modulemanager: Support for shared modules - function module.add_host(host_module) in a global module
Matthew Wild <mwild1@gmail.com>
parents:
4641
diff
changeset
|
228 end |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
229 return nil, "global-module-already-loaded"; |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
230 end |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5411
diff
changeset
|
231 |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
232 |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
233 |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
234 local _log = logger.init(host..":"..module_name); |
|
5021
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4896
diff
changeset
|
235 local api_instance = setmetatable({ name = module_name, host = host, |
|
6661
90e846e8a788
modulemanager: Add luacheck annotations
Matthew Wild <mwild1@gmail.com>
parents:
6660
diff
changeset
|
236 _log = _log, log = function (self, ...) return _log(...); end, --luacheck: ignore 212/self |
|
90e846e8a788
modulemanager: Add luacheck annotations
Matthew Wild <mwild1@gmail.com>
parents:
6660
diff
changeset
|
237 event_handlers = new_multitable(), reloading = not not state, |
|
90e846e8a788
modulemanager: Add luacheck annotations
Matthew Wild <mwild1@gmail.com>
parents:
6660
diff
changeset
|
238 saved_state = state~=true and state or nil } |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
239 , { __index = api }); |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
240 |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
241 local pluginenv = setmetatable({ module = api_instance }, { __index = _G }); |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
242 api_instance.environment = pluginenv; |
|
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
5411
diff
changeset
|
243 |
|
12275
13624194984b
core.modulemanager: Save module metadata for potential later use
Kim Alvefur <zash@zash.se>
parents:
12257
diff
changeset
|
244 local mod, err, meta = loader:load_code(module_name, nil, pluginenv); |
|
5021
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4896
diff
changeset
|
245 if not mod then |
|
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4896
diff
changeset
|
246 log("error", "Unable to load module '%s': %s", module_name or "nil", err or "nil"); |
|
9867
984f27e4b8a3
modulemanager: Set module status on successful or failed module load
Matthew Wild <mwild1@gmail.com>
parents:
9563
diff
changeset
|
247 api_instance:set_status("error", "Failed to load (see log)"); |
|
5021
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4896
diff
changeset
|
248 return nil, err; |
|
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4896
diff
changeset
|
249 end |
|
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4896
diff
changeset
|
250 |
|
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4896
diff
changeset
|
251 api_instance.path = err; |
|
12275
13624194984b
core.modulemanager: Save module metadata for potential later use
Kim Alvefur <zash@zash.se>
parents:
12257
diff
changeset
|
252 api_instance.meta = meta; |
|
5021
85b2689dbcfe
Eliminate direct setfenv usage
Florian Zeitz <florob@babelmonkeys.de>
parents:
4896
diff
changeset
|
253 |
|
11145
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
254 local custom_plugins = prosody.paths.installer; |
|
11151
498b3ab49b9c
core.modulemanager: Fix error if installer path missing
Kim Alvefur <zash@zash.se>
parents:
11147
diff
changeset
|
255 if custom_plugins and err:sub(1, #custom_plugins+1) == custom_plugins.."/" then |
|
11145
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
256 -- Stage 1: Make it work (you are here) |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
257 -- Stage 2: Make it less hacky (TODO) |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
258 local manifest = {}; |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
259 local luarocks_path = custom_plugins.."/lib/luarocks/rocks-"..lua_version; |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
260 local manifest_filename = luarocks_path.."/manifest"; |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
261 local load_manifest, err = envload.envloadfile(manifest_filename, manifest); |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
262 if not load_manifest then |
|
11147
82d6c8e627b9
core.modulemanager: Add compat for LuaRocks 2.x
Kim Alvefur <zash@zash.se>
parents:
11145
diff
changeset
|
263 -- COMPAT Luarocks 2.x |
|
82d6c8e627b9
core.modulemanager: Add compat for LuaRocks 2.x
Kim Alvefur <zash@zash.se>
parents:
11145
diff
changeset
|
264 log("debug", "Could not load LuaRocks 3.x manifest, trying 2.x", err); |
|
11287
b602dd3c4bbc
core.modulemanager: Fix resource location compat with LuaRocks 2.x
Kim Alvefur <zash@zash.se>
parents:
11151
diff
changeset
|
265 luarocks_path = custom_plugins.."/lib/luarocks/rocks"; |
|
11147
82d6c8e627b9
core.modulemanager: Add compat for LuaRocks 2.x
Kim Alvefur <zash@zash.se>
parents:
11145
diff
changeset
|
266 manifest_filename = luarocks_path.."/manifest"; |
|
82d6c8e627b9
core.modulemanager: Add compat for LuaRocks 2.x
Kim Alvefur <zash@zash.se>
parents:
11145
diff
changeset
|
267 load_manifest, err = envload.envloadfile(manifest_filename, manifest); |
|
82d6c8e627b9
core.modulemanager: Add compat for LuaRocks 2.x
Kim Alvefur <zash@zash.se>
parents:
11145
diff
changeset
|
268 end |
|
82d6c8e627b9
core.modulemanager: Add compat for LuaRocks 2.x
Kim Alvefur <zash@zash.se>
parents:
11145
diff
changeset
|
269 if not load_manifest then |
|
11145
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
270 log("error", "Could not load manifest of installed plugins: %s", err, load_manifest); |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
271 else |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
272 local ok, err = xpcall(load_manifest, debug_traceback); |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
273 if not ok then |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
274 log("error", "Could not load manifest of installed plugins: %s", err); |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
275 elseif type(manifest.modules) ~= "table" then |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
276 log("debug", "Expected 'table' but manifest.modules = %q", manifest.modules); |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
277 log("error", "Can't look up resource path for mod_%s because '%s' does not appear to be a LuaRocks manifest", module_name, manifest_filename); |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
278 else |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
279 local versions = manifest.modules["mod_"..module_name]; |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
280 if type(versions) == "table" and versions[1] then |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
281 -- Not going to deal with multiple installed versions |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
282 api_instance.resource_path = luarocks_path.."/"..versions[1]; |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
283 else |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
284 log("debug", "mod_%s does not appear in the installation manifest", module_name); |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
285 end |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
286 end |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
287 end |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
288 end |
|
be73df6765b9
core.modulemanager: Locate resources of LuaRocks-installed modules
Kim Alvefur <zash@zash.se>
parents:
10530
diff
changeset
|
289 |
|
4776
dbe9d75c0452
modulemanager: Fixes to handle circular dependencies in module:depends()
Matthew Wild <mwild1@gmail.com>
parents:
4746
diff
changeset
|
290 modulemap[host][module_name] = pluginenv; |
|
9563
732314eb3258
modulemanager: Fix issues introduced in previous commit acf74ad0b795 [thanks luacheck, scansion]
Matthew Wild <mwild1@gmail.com>
parents:
9562
diff
changeset
|
291 local ok, err = xpcall(mod, debug_traceback); |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
292 if ok then |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
293 -- Call module's "load" |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
294 if module_has_method(pluginenv, "load") then |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
295 ok, err = call_module_method(pluginenv, "load"); |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
296 if not ok then |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
297 log("warn", "Error loading module '%s' on '%s': %s", module_name, host, err or "nil"); |
|
9867
984f27e4b8a3
modulemanager: Set module status on successful or failed module load
Matthew Wild <mwild1@gmail.com>
parents:
9563
diff
changeset
|
298 api_instance:set_status("warn", "Error during load (see log)"); |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
299 end |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
300 end |
|
5192
3fc3a3072cc2
modulemanager: Set module.reloading when a module is reloading, and when loading make the saved state available in module.saved_state (if any)
Matthew Wild <mwild1@gmail.com>
parents:
5123
diff
changeset
|
301 api_instance.reloading, api_instance.saved_state = nil, nil; |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
302 |
|
4639
98a29138dec8
modulemanager: Use api_instance rather than pluginenv.module (same thing)
Matthew Wild <mwild1@gmail.com>
parents:
4638
diff
changeset
|
303 if api_instance.host == "*" then |
|
98a29138dec8
modulemanager: Use api_instance rather than pluginenv.module (same thing)
Matthew Wild <mwild1@gmail.com>
parents:
4638
diff
changeset
|
304 if not api_instance.global then -- COMPAT w/pre-0.9 |
|
4801
83cedf648b46
modulemanager: Hide deprecation warning for modules loaded on '*' directly (e.g. prosodyctl mod_<command>) (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
4776
diff
changeset
|
305 if host ~= "*" then |
|
83cedf648b46
modulemanager: Hide deprecation warning for modules loaded on '*' directly (e.g. prosodyctl mod_<command>) (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
4776
diff
changeset
|
306 log("warn", "mod_%s: Setting module.host = '*' deprecated, call module:set_global() instead", module_name); |
|
83cedf648b46
modulemanager: Hide deprecation warning for modules loaded on '*' directly (e.g. prosodyctl mod_<command>) (thanks Zash)
Matthew Wild <mwild1@gmail.com>
parents:
4776
diff
changeset
|
307 end |
|
4606
17785dbd9d58
modulemanager: Some refactoring. Deprecate module.host = "*", modules should call module:set_global() (which has been around since forever)
Matthew Wild <mwild1@gmail.com>
parents:
4604
diff
changeset
|
308 api_instance:set_global(); |
|
17785dbd9d58
modulemanager: Some refactoring. Deprecate module.host = "*", modules should call module:set_global() (which has been around since forever)
Matthew Wild <mwild1@gmail.com>
parents:
4604
diff
changeset
|
309 end |
|
4776
dbe9d75c0452
modulemanager: Fixes to handle circular dependencies in module:depends()
Matthew Wild <mwild1@gmail.com>
parents:
4746
diff
changeset
|
310 modulemap[host][module_name] = nil; |
|
dbe9d75c0452
modulemanager: Fixes to handle circular dependencies in module:depends()
Matthew Wild <mwild1@gmail.com>
parents:
4746
diff
changeset
|
311 modulemap[api_instance.host][module_name] = pluginenv; |
|
4643
9008fc396fb1
modulemanager: When a shared module becomes global, ensure it still gets loaded onto the original target host
Matthew Wild <mwild1@gmail.com>
parents:
4642
diff
changeset
|
312 if host ~= api_instance.host and module_has_method(pluginenv, "add_host") then |
|
9008fc396fb1
modulemanager: When a shared module becomes global, ensure it still gets loaded onto the original target host
Matthew Wild <mwild1@gmail.com>
parents:
4642
diff
changeset
|
313 -- Now load the module again onto the host it was originally being loaded on |
|
4662
105423f77d46
modulemanager: Report errors that happen when loading a shared module onto its original host
Matthew Wild <mwild1@gmail.com>
parents:
4652
diff
changeset
|
314 ok, err = do_load_module(host, module_name); |
|
4643
9008fc396fb1
modulemanager: When a shared module becomes global, ensure it still gets loaded onto the original target host
Matthew Wild <mwild1@gmail.com>
parents:
4642
diff
changeset
|
315 end |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
316 end |
|
13361
e20949a10118
modulemanager: Allow modules to expose module.ready - to be called after init
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
317 |
|
e20949a10118
modulemanager: Allow modules to expose module.ready - to be called after init
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
318 if module_has_method(pluginenv, "ready") then |
|
e20949a10118
modulemanager: Allow modules to expose module.ready - to be called after init
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
319 pluginenv.module:on_ready(pluginenv.module.ready); |
|
e20949a10118
modulemanager: Allow modules to expose module.ready - to be called after init
Matthew Wild <mwild1@gmail.com>
parents:
12972
diff
changeset
|
320 end |
|
4606
17785dbd9d58
modulemanager: Some refactoring. Deprecate module.host = "*", modules should call module:set_global() (which has been around since forever)
Matthew Wild <mwild1@gmail.com>
parents:
4604
diff
changeset
|
321 end |
|
17785dbd9d58
modulemanager: Some refactoring. Deprecate module.host = "*", modules should call module:set_global() (which has been around since forever)
Matthew Wild <mwild1@gmail.com>
parents:
4604
diff
changeset
|
322 if not ok then |
|
4776
dbe9d75c0452
modulemanager: Fixes to handle circular dependencies in module:depends()
Matthew Wild <mwild1@gmail.com>
parents:
4746
diff
changeset
|
323 modulemap[api_instance.host][module_name] = nil; |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
324 log("error", "Error initializing module '%s' on '%s': %s", module_name, host, err or "nil"); |
|
9867
984f27e4b8a3
modulemanager: Set module status on successful or failed module load
Matthew Wild <mwild1@gmail.com>
parents:
9563
diff
changeset
|
325 api_instance:set_status("warn", "Error during load (see log)"); |
|
984f27e4b8a3
modulemanager: Set module status on successful or failed module load
Matthew Wild <mwild1@gmail.com>
parents:
9563
diff
changeset
|
326 else |
|
984f27e4b8a3
modulemanager: Set module status on successful or failed module load
Matthew Wild <mwild1@gmail.com>
parents:
9563
diff
changeset
|
327 api_instance:set_status("core", "Loaded", false); |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
328 end |
|
4537
d8d257c13562
modulemanager: load(): Return and use the correct module object
Matthew Wild <mwild1@gmail.com>
parents:
4535
diff
changeset
|
329 return ok and pluginenv, err; |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
330 end |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
331 |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
332 local function do_reload_module(host, name) |
|
745
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
333 local mod = get_module(host, name); |
|
710
56f6c115bc69
modulemanager: Added reload support, with callbacks for saving and restoring state
Waqas Hussain <waqas20@gmail.com>
parents:
709
diff
changeset
|
334 if not mod then return nil, "module-not-loaded"; end |
|
56f6c115bc69
modulemanager: Added reload support, with callbacks for saving and restoring state
Waqas Hussain <waqas20@gmail.com>
parents:
709
diff
changeset
|
335 |
|
12253
57d35fcde488
modulemanager, moduleapi: Switch to new pluginloader interface
Matthew Wild <mwild1@gmail.com>
parents:
12146
diff
changeset
|
336 local _mod, err = loader:load_code(name); -- checking for syntax errors |
|
713
2afd6d9e21cd
modulemanager: Check for syntax errors before reloading a module
Waqas Hussain <waqas20@gmail.com>
parents:
710
diff
changeset
|
337 if not _mod then |
|
1386
9132f16666e4
modulemanager: Fix copy/paste error, should be name instead of module_name
Matthew Wild <mwild1@gmail.com>
parents:
1378
diff
changeset
|
338 log("error", "Unable to load module '%s': %s", name or "nil", err or "nil"); |
|
713
2afd6d9e21cd
modulemanager: Check for syntax errors before reloading a module
Waqas Hussain <waqas20@gmail.com>
parents:
710
diff
changeset
|
339 return nil, err; |
|
2afd6d9e21cd
modulemanager: Check for syntax errors before reloading a module
Waqas Hussain <waqas20@gmail.com>
parents:
710
diff
changeset
|
340 end |
|
2afd6d9e21cd
modulemanager: Check for syntax errors before reloading a module
Waqas Hussain <waqas20@gmail.com>
parents:
710
diff
changeset
|
341 |
|
710
56f6c115bc69
modulemanager: Added reload support, with callbacks for saving and restoring state
Waqas Hussain <waqas20@gmail.com>
parents:
709
diff
changeset
|
342 local saved; |
|
745
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
343 if module_has_method(mod, "save") then |
|
10530
67d56dacc79c
core.modulemanager: Silence warning about unused err variable [luacheck]
Kim Alvefur <zash@zash.se>
parents:
10434
diff
changeset
|
344 -- FIXME What goes in 'err' here? |
|
67d56dacc79c
core.modulemanager: Silence warning about unused err variable [luacheck]
Kim Alvefur <zash@zash.se>
parents:
10434
diff
changeset
|
345 local ok, ret, err = call_module_method(mod, "save"); -- luacheck: ignore 211/err |
|
745
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
346 if ok then |
|
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
347 saved = ret; |
|
710
56f6c115bc69
modulemanager: Added reload support, with callbacks for saving and restoring state
Waqas Hussain <waqas20@gmail.com>
parents:
709
diff
changeset
|
348 else |
|
4383
718445c040c4
modulemanager: Fix undefined global access in handling of module.save error handling.
Waqas Hussain <waqas20@gmail.com>
parents:
4381
diff
changeset
|
349 log("warn", "Error saving module '%s:%s' state: %s", host, name, ret); |
|
5377
898454038524
core.*: Complete removal of all traces of the "core" section and section-related code.
Kim Alvefur <zash@zash.se>
parents:
5192
diff
changeset
|
350 if not config.get(host, "force_module_reload") then |
|
745
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
351 log("warn", "Aborting reload due to error, set force_module_reload to ignore this"); |
|
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
352 return nil, "save-state-failed"; |
|
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
353 else |
|
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
354 log("warn", "Continuing with reload (using the force)"); |
|
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
355 end |
|
710
56f6c115bc69
modulemanager: Added reload support, with callbacks for saving and restoring state
Waqas Hussain <waqas20@gmail.com>
parents:
709
diff
changeset
|
356 end |
|
56f6c115bc69
modulemanager: Added reload support, with callbacks for saving and restoring state
Waqas Hussain <waqas20@gmail.com>
parents:
709
diff
changeset
|
357 end |
|
56f6c115bc69
modulemanager: Added reload support, with callbacks for saving and restoring state
Waqas Hussain <waqas20@gmail.com>
parents:
709
diff
changeset
|
358 |
|
5192
3fc3a3072cc2
modulemanager: Set module.reloading when a module is reloading, and when loading make the saved state available in module.saved_state (if any)
Matthew Wild <mwild1@gmail.com>
parents:
5123
diff
changeset
|
359 mod.module.reloading = true; |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
360 do_unload_module(host, name); |
|
5192
3fc3a3072cc2
modulemanager: Set module.reloading when a module is reloading, and when loading make the saved state available in module.saved_state (if any)
Matthew Wild <mwild1@gmail.com>
parents:
5123
diff
changeset
|
361 local ok, err = do_load_module(host, name, saved or true); |
|
745
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
362 if ok then |
|
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
363 mod = get_module(host, name); |
|
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
364 if module_has_method(mod, "restore") then |
|
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
365 local ok, err = call_module_method(mod, "restore", saved or {}) |
|
710
56f6c115bc69
modulemanager: Added reload support, with callbacks for saving and restoring state
Waqas Hussain <waqas20@gmail.com>
parents:
709
diff
changeset
|
366 if (not ok) and err then |
|
745
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
367 log("warn", "Error restoring module '%s' from '%s': %s", name, host, err); |
|
710
56f6c115bc69
modulemanager: Added reload support, with callbacks for saving and restoring state
Waqas Hussain <waqas20@gmail.com>
parents:
709
diff
changeset
|
368 end |
|
56f6c115bc69
modulemanager: Added reload support, with callbacks for saving and restoring state
Waqas Hussain <waqas20@gmail.com>
parents:
709
diff
changeset
|
369 end |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
370 end |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
371 return ok and mod, err; |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
372 end |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
373 |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
374 --- Public API --- |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
375 |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
376 -- Load a module and fire module-loaded event |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
377 function load(host, name) |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
378 local mod, err = do_load_module(host, name); |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
379 if mod then |
|
4804
607414b26c8c
modulemanager: Pass the module's final host (e.g. '*') to the module-loaded event
Matthew Wild <mwild1@gmail.com>
parents:
4801
diff
changeset
|
380 (hosts[mod.module.host] or prosody).events.fire_event("module-loaded", { module = name, host = mod.module.host }); |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
381 end |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
382 return mod, err; |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
383 end |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
384 |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
385 -- Unload a module and fire module-unloaded |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
386 function unload(host, name) |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
387 local ok, err = do_unload_module(host, name); |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
388 if ok then |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
389 (hosts[host] or prosody).events.fire_event("module-unloaded", { module = name, host = host }); |
|
710
56f6c115bc69
modulemanager: Added reload support, with callbacks for saving and restoring state
Waqas Hussain <waqas20@gmail.com>
parents:
709
diff
changeset
|
390 end |
|
745
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
391 return ok, err; |
|
710
56f6c115bc69
modulemanager: Added reload support, with callbacks for saving and restoring state
Waqas Hussain <waqas20@gmail.com>
parents:
709
diff
changeset
|
392 end |
|
56f6c115bc69
modulemanager: Added reload support, with callbacks for saving and restoring state
Waqas Hussain <waqas20@gmail.com>
parents:
709
diff
changeset
|
393 |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
394 function reload(host, name) |
|
4853
4ca9328e37d5
modulemanager: Set module.reloading = true when firing module-reloaded event
Matthew Wild <mwild1@gmail.com>
parents:
4804
diff
changeset
|
395 local mod, err = do_reload_module(host, name); |
|
4ca9328e37d5
modulemanager: Set module.reloading = true when firing module-reloaded event
Matthew Wild <mwild1@gmail.com>
parents:
4804
diff
changeset
|
396 if mod then |
|
4ca9328e37d5
modulemanager: Set module.reloading = true when firing module-reloaded event
Matthew Wild <mwild1@gmail.com>
parents:
4804
diff
changeset
|
397 modulemap[host][name].module.reloading = true; |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
398 (hosts[host] or prosody).events.fire_event("module-reloaded", { module = name, host = host }); |
|
4853
4ca9328e37d5
modulemanager: Set module.reloading = true when firing module-reloaded event
Matthew Wild <mwild1@gmail.com>
parents:
4804
diff
changeset
|
399 mod.module.reloading = nil; |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
400 elseif not is_loaded(host, name) then |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
401 (hosts[host] or prosody).events.fire_event("module-unloaded", { module = name, host = host }); |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
402 end |
|
4853
4ca9328e37d5
modulemanager: Set module.reloading = true when firing module-reloaded event
Matthew Wild <mwild1@gmail.com>
parents:
4804
diff
changeset
|
403 return mod, err; |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
404 end |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
405 |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
406 function get_module(host, name) |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
407 return modulemap[host] and modulemap[host][name]; |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
408 end |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
409 |
|
5410
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
410 function get_items(key, host) |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
411 local result = {}; |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
412 local modules = modulemap[host]; |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
413 if not key or not host or not modules then return nil; end |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
414 |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
415 for _, module in pairs(modules) do |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
416 local mod = module.module; |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
417 if mod.items and mod.items[key] then |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
418 for _, value in ipairs(mod.items[key]) do |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
419 t_insert(result, value); |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
420 end |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
421 end |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
422 end |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
423 |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
424 return result; |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
425 end |
|
bea93cfd6c54
modulemanager: add function to retrieve module items from a specific host entity.
Marco Cirillo <maranda@lightwitch.org>
parents:
5377
diff
changeset
|
426 |
|
4532
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
427 function get_modules(host) |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
428 return modulemap[host]; |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
429 end |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
430 |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
431 function is_loaded(host, name) |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
432 return modulemap[host] and modulemap[host][name] and true; |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
433 end |
|
d8dbf569766c
modulemanager: Some reorganisation. Only external change is (should be) that module-unloaded and module-loaded are no longer fired when reloading a module, the new event module-reloaded is fired instead.
Matthew Wild <mwild1@gmail.com>
parents:
4531
diff
changeset
|
434 |
|
745
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
435 function module_has_method(module, method) |
|
4641
2b3ee52fba32
modulemanager: Make module_has_method and module_call_method use rawget()
Matthew Wild <mwild1@gmail.com>
parents:
4640
diff
changeset
|
436 return type(rawget(module.module, method)) == "function"; |
|
745
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
437 end |
|
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
438 |
|
747
40837f3422ab
modulemanager: Add get_host_type() API method, and fix up call_module_method to work properly
Matthew Wild <mwild1@gmail.com>
parents:
746
diff
changeset
|
439 function call_module_method(module, method, ...) |
|
4641
2b3ee52fba32
modulemanager: Make module_has_method and module_call_method use rawget()
Matthew Wild <mwild1@gmail.com>
parents:
4640
diff
changeset
|
440 local f = rawget(module.module, method); |
|
2b3ee52fba32
modulemanager: Make module_has_method and module_call_method use rawget()
Matthew Wild <mwild1@gmail.com>
parents:
4640
diff
changeset
|
441 if type(f) == "function" then |
|
9563
732314eb3258
modulemanager: Fix issues introduced in previous commit acf74ad0b795 [thanks luacheck, scansion]
Matthew Wild <mwild1@gmail.com>
parents:
9562
diff
changeset
|
442 return xpcall(f, debug_traceback, ...); |
|
745
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
443 else |
|
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
444 return false, "no-such-method"; |
|
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
445 end |
|
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
446 end |
|
5a343599cd3e
core.modulemanager: Some refactoring to make upcoming changes a little easier
Matthew Wild <mwild1@gmail.com>
parents:
733
diff
changeset
|
447 |
|
6779
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6661
diff
changeset
|
448 return { |
|
8916
e727747279a0
modulemanager: Expose function to get the list of modules that should be loaded on a host
Matthew Wild <mwild1@gmail.com>
parents:
8717
diff
changeset
|
449 get_modules_for_host = get_modules_for_host; |
|
6779
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6661
diff
changeset
|
450 load_modules_for_host = load_modules_for_host; |
|
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6661
diff
changeset
|
451 load = load; |
|
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6661
diff
changeset
|
452 unload = unload; |
|
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6661
diff
changeset
|
453 reload = reload; |
|
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6661
diff
changeset
|
454 get_module = get_module; |
|
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6661
diff
changeset
|
455 get_items = get_items; |
|
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6661
diff
changeset
|
456 get_modules = get_modules; |
|
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6661
diff
changeset
|
457 is_loaded = is_loaded; |
|
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6661
diff
changeset
|
458 module_has_method = module_has_method; |
|
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6661
diff
changeset
|
459 call_module_method = call_module_method; |
|
12253
57d35fcde488
modulemanager, moduleapi: Switch to new pluginloader interface
Matthew Wild <mwild1@gmail.com>
parents:
12146
diff
changeset
|
460 |
|
57d35fcde488
modulemanager, moduleapi: Switch to new pluginloader interface
Matthew Wild <mwild1@gmail.com>
parents:
12146
diff
changeset
|
461 loader = loader; |
|
6779
6236668da30a
core.*: Remove use of module() function
Kim Alvefur <zash@zash.se>
parents:
6661
diff
changeset
|
462 }; |