+function reload(host, name, ...)
+ local mod = get_module(host, name);
+ if not mod then return nil, "module-not-loaded"; end
+
+ local _mod, err = loadfile(get_module_filename(name)); -- checking for syntax errors
+ if not _mod then
+ log("error", "Unable to load module '%s': %s", module_name or "nil", err or "nil");
+ return nil, err;
+ end
+
+ local saved;
+
+ if module_has_method(mod, "save") then
+ local ok, ret, err = call_module_method(mod, "save");
+ if ok then
+ saved = ret;
+ else
+ log("warn", "Error saving module '%s:%s' state: %s", host, module, ret);
+ if not config.get(host, "core", "force_module_reload") then
+ log("warn", "Aborting reload due to error, set force_module_reload to ignore this");
+ return nil, "save-state-failed";
+ else
+ log("warn", "Continuing with reload (using the force)");
+ end
+ end
+ end
+
+ unload(host, name, ...);
+ local ok, err = load(host, name, ...);
+ if ok then
+ mod = get_module(host, name);
+ if module_has_method(mod, "restore") then
+ local ok, err = call_module_method(mod, "restore", saved or {})
+ if (not ok) and err then
+ log("warn", "Error restoring module '%s' from '%s': %s", name, host, err);
+ end
+ end
+ return true;
+ end
+ return ok, err;
+end
+