# HG changeset patch # User Matthew Wild # Date 1643983906 0 # Node ID 57d35fcde4885962c0d08e45615bca1d26f972de # Parent 4bfe658415a0b5f19e760fec0346599a5db568a3 modulemanager, moduleapi: Switch to new pluginloader interface diff -r 4bfe658415a0 -r 57d35fcde488 core/moduleapi.lua --- a/core/moduleapi.lua Fri Feb 04 14:10:34 2022 +0000 +++ b/core/moduleapi.lua Fri Feb 04 14:11:46 2022 +0000 @@ -10,7 +10,6 @@ local set = require "util.set"; local it = require "util.iterators"; local logger = require "util.logger"; -local pluginloader = require "util.pluginloader"; local timer = require "util.timer"; local resolve_relative_path = require"util.paths".resolve_relative_path; local st = require "util.stanza"; @@ -129,7 +128,8 @@ end function api:require(lib) - local f, n = pluginloader.load_code_ext(self.name, lib, "lib.lua", self.environment); + local modulemanager = require"core.modulemanager"; + local f, n = modulemanager.loader:load_code_ext(self.name, lib, "lib.lua", self.environment); if not f then error("Failed to load plugin library '"..lib.."', error: "..n); end -- FIXME better error message return f(); end diff -r 4bfe658415a0 -r 57d35fcde488 core/modulemanager.lua --- a/core/modulemanager.lua Fri Feb 04 14:10:34 2022 +0000 +++ b/core/modulemanager.lua Fri Feb 04 14:11:46 2022 +0000 @@ -52,6 +52,9 @@ local _ENV = nil; -- luacheck: std none +local loader = pluginloader.init({ +}); + local load_modules_for_host, load, unload, reload, get_module, get_items; local get_modules, is_loaded, module_has_method, call_module_method; @@ -184,7 +187,7 @@ local pluginenv = setmetatable({ module = api_instance }, { __index = _G }); api_instance.environment = pluginenv; - local mod, err = pluginloader.load_code(module_name, nil, pluginenv); + local mod, err = loader:load_code(module_name, nil, pluginenv); if not mod then log("error", "Unable to load module '%s': %s", module_name or "nil", err or "nil"); api_instance:set_status("error", "Failed to load (see log)"); @@ -271,7 +274,7 @@ local mod = get_module(host, name); if not mod then return nil, "module-not-loaded"; end - local _mod, err = pluginloader.load_code(name); -- checking for syntax errors + local _mod, err = loader:load_code(name); -- checking for syntax errors if not _mod then log("error", "Unable to load module '%s': %s", name or "nil", err or "nil"); return nil, err; @@ -395,4 +398,6 @@ is_loaded = is_loaded; module_has_method = module_has_method; call_module_method = call_module_method; + + loader = loader; };