Changeset

1394:2ebed659b958

Automated merge with http://waqas.ath.cx:8000/
author Matthew Wild <mwild1@gmail.com>
date Tue, 23 Jun 2009 15:58:56 +0100
parents 1393:576143941a76 (diff) 1391:b910ef82622d (current diff)
children 1395:1c547fb4e570
files core/modulemanager.lua
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/core/modulemanager.lua	Tue Jun 23 15:40:30 2009 +0100
+++ b/core/modulemanager.lua	Tue Jun 23 15:58:56 2009 +0100
@@ -30,7 +30,7 @@
 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 @@
 	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 = {};