comparison core/moduleapi.lua @ 13719:4309c934e813 13.0

moduleapi: Allow soft dependencies via module:depends(mod, true)
author Matthew Wild <mwild1@gmail.com>
date Sun, 16 Feb 2025 13:29:07 +0000
parents a4217361c1c6
children e6c6f58dfda1 3e6bb6ffbd43
comparison
equal deleted inserted replaced
13718:569fae28a2f3 13719:4309c934e813
134 local f, n = modulemanager.loader:load_code_ext(self.name, lib, "lib.lua", self.environment); 134 local f, n = modulemanager.loader:load_code_ext(self.name, lib, "lib.lua", self.environment);
135 if not f then error("Failed to load plugin library '"..lib.."', error: "..n); end -- FIXME better error message 135 if not f then error("Failed to load plugin library '"..lib.."', error: "..n); end -- FIXME better error message
136 return f(); 136 return f();
137 end 137 end
138 138
139 function api:depends(name) 139 function api:depends(name, soft)
140 local modulemanager = require"prosody.core.modulemanager"; 140 local modulemanager = require"prosody.core.modulemanager";
141 if self:get_option_inherited_set("modules_disabled", {}):contains(name) then 141 if self:get_option_inherited_set("modules_disabled", {}):contains(name) then
142 error("Dependency on disabled module mod_"..name); 142 if not soft then
143 error("Dependency on disabled module mod_"..name);
144 end
145 self:log("debug", "Not loading disabled soft dependency mod_%s", name);
146 return nil, "disabled";
143 end 147 end
144 if not self.dependencies then 148 if not self.dependencies then
145 self.dependencies = {}; 149 self.dependencies = {};
146 self:hook("module-reloaded", function (event) 150 self:hook("module-reloaded", function (event)
147 if self.dependencies[event.module] and not self.reloading then 151 if self.dependencies[event.module] and not self.reloading then