Automated merge with http://waqas.ath.cx:8000/
authorMatthew Wild <mwild1@gmail.com>
Tue, 23 Jun 2009 14:58:56 +0000 (15:58 +0100)
committerMatthew Wild <mwild1@gmail.com>
Tue, 23 Jun 2009 14:58:56 +0000 (15:58 +0100)
core/modulemanager.lua

index 19e0a98272d440d8b3d50533d4051b6196645b6c..082dcbb80360707b5dac25137f93a5bef34bfc35 100644 (file)
@@ -30,7 +30,7 @@ local t_insert, t_concat = table.insert, table.concat;
 local type = type;
 local next = next;
 local rawget = rawget;
-
+local error = error;
 local tostring = tostring;
 
 -- We need this to let modules access the real global namespace
@@ -408,6 +408,16 @@ function api:hook_stanza(xmlns, name, handler, priority)
        return api.hook(self, "stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end, priority);
 end
 
+function api:require(lib)
+       local f, n = pluginloader.load_code(self.name, lib..".lib.lua");
+       if not f then
+               f, n = pluginloader.load_code(lib, lib..".lib.lua");
+       end
+       if not f then error("Failed to load plugin library '"..lib.."', error: "..n); end -- FIXME better error message
+       setfenv(f, setmetatable({ module = self }, { __index = _G }));
+       return f();
+end
+
 --------------------------------------------------------------------
 
 local actions = {};