Changeset

12253:57d35fcde488

modulemanager, moduleapi: Switch to new pluginloader interface
author Matthew Wild <mwild1@gmail.com>
date Fri, 04 Feb 2022 14:11:46 +0000
parents 12252:4bfe658415a0
children 12254:5b0c8e499288
files core/moduleapi.lua core/modulemanager.lua
diffstat 2 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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;
 };