Software /
code /
prosody
Comparison
core/modulemanager.lua @ 12253:57d35fcde488
modulemanager, moduleapi: Switch to new pluginloader interface
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 04 Feb 2022 14:11:46 +0000 |
parent | 12146:9c69c062d6b7 |
child | 12254:5b0c8e499288 |
comparison
equal
deleted
inserted
replaced
12252:4bfe658415a0 | 12253:57d35fcde488 |
---|---|
50 local _G = _G; | 50 local _G = _G; |
51 | 51 |
52 local _ENV = nil; | 52 local _ENV = nil; |
53 -- luacheck: std none | 53 -- luacheck: std none |
54 | 54 |
55 local loader = pluginloader.init({ | |
56 }); | |
57 | |
55 local load_modules_for_host, load, unload, reload, get_module, get_items; | 58 local load_modules_for_host, load, unload, reload, get_module, get_items; |
56 local get_modules, is_loaded, module_has_method, call_module_method; | 59 local get_modules, is_loaded, module_has_method, call_module_method; |
57 | 60 |
58 -- [host] = { [module] = module_env } | 61 -- [host] = { [module] = module_env } |
59 local modulemap = { ["*"] = {} }; | 62 local modulemap = { ["*"] = {} }; |
182 , { __index = api }); | 185 , { __index = api }); |
183 | 186 |
184 local pluginenv = setmetatable({ module = api_instance }, { __index = _G }); | 187 local pluginenv = setmetatable({ module = api_instance }, { __index = _G }); |
185 api_instance.environment = pluginenv; | 188 api_instance.environment = pluginenv; |
186 | 189 |
187 local mod, err = pluginloader.load_code(module_name, nil, pluginenv); | 190 local mod, err = loader:load_code(module_name, nil, pluginenv); |
188 if not mod then | 191 if not mod then |
189 log("error", "Unable to load module '%s': %s", module_name or "nil", err or "nil"); | 192 log("error", "Unable to load module '%s': %s", module_name or "nil", err or "nil"); |
190 api_instance:set_status("error", "Failed to load (see log)"); | 193 api_instance:set_status("error", "Failed to load (see log)"); |
191 return nil, err; | 194 return nil, err; |
192 end | 195 end |
269 | 272 |
270 local function do_reload_module(host, name) | 273 local function do_reload_module(host, name) |
271 local mod = get_module(host, name); | 274 local mod = get_module(host, name); |
272 if not mod then return nil, "module-not-loaded"; end | 275 if not mod then return nil, "module-not-loaded"; end |
273 | 276 |
274 local _mod, err = pluginloader.load_code(name); -- checking for syntax errors | 277 local _mod, err = loader:load_code(name); -- checking for syntax errors |
275 if not _mod then | 278 if not _mod then |
276 log("error", "Unable to load module '%s': %s", name or "nil", err or "nil"); | 279 log("error", "Unable to load module '%s': %s", name or "nil", err or "nil"); |
277 return nil, err; | 280 return nil, err; |
278 end | 281 end |
279 | 282 |
393 get_items = get_items; | 396 get_items = get_items; |
394 get_modules = get_modules; | 397 get_modules = get_modules; |
395 is_loaded = is_loaded; | 398 is_loaded = is_loaded; |
396 module_has_method = module_has_method; | 399 module_has_method = module_has_method; |
397 call_module_method = call_module_method; | 400 call_module_method = call_module_method; |
401 | |
402 loader = loader; | |
398 }; | 403 }; |