# HG changeset patch # User Waqas Hussain # Date 1231868227 -18000 # Node ID 56f6c115bc694c9096d41719566ab068f4983629 # Parent 8bb83563cb21d5e0d8e5d477cd297aaab35e53e3 modulemanager: Added reload support, with callbacks for saving and restoring state diff -r 8bb83563cb21 -r 56f6c115bc69 core/modulemanager.lua --- a/core/modulemanager.lua Tue Jan 13 15:29:00 2009 +0000 +++ b/core/modulemanager.lua Tue Jan 13 22:37:07 2009 +0500 @@ -140,8 +140,8 @@ local mod = modulemap[host] and modulemap[host][name]; if not mod then return nil, "module-not-loaded"; end - if type(rawget(mod, "unload")) == "function" then - local ok, err = pcall(rawget(mod, "unload"), ...) + if type(mod.module.unload) == "function" then + local ok, err = pcall(mod.module.unload, ...) if (not ok) and err then log("warn", "Non-fatal error unloading module '%s' from '%s': %s", name, host, err); end @@ -160,6 +160,33 @@ return true; end +function reload(host, name, ...) + local mod = modulemap[host] and modulemap[host][name]; + if not mod then return nil, "module-not-loaded"; end + + local saved; + if type(mod.module.save) == "function" then + local ok, err = pcall(mod.module.save) + if (not ok) and err then + log("warn", "Non-fatal error unloading module '%s' from '%s': %s", name, host, err); + else + saved = err; + end + end + + unload(host, name, ...); + if load(host, name, ...) then + mod = modulemap[host] and modulemap[host][name]; + if type(mod.module.restore) == "function" then + local ok, err = pcall(mod.module.restore, saved or {}) + if (not ok) and err then + log("warn", "Non-fatal error unloading module '%s' from '%s': %s", name, host, err); + end + end + return true; + end +end + function handle_stanza(host, origin, stanza) local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns, origin.type; if name == "iq" and xmlns == "jabber:client" then