Comparison

core/modulemanager.lua @ 1392:9935ddfd8ccf

modulemanager: Added simple module:require implementation
author Waqas Hussain <waqas20@gmail.com>
date Sun, 21 Jun 2009 19:15:59 +0500
parent 1361:4e56889c33e1
child 1393:576143941a76
comparison
equal deleted inserted replaced
1377:ae88b9dc7890 1392:9935ddfd8ccf
28 local pairs, ipairs = pairs, ipairs; 28 local pairs, ipairs = pairs, ipairs;
29 local t_insert, t_concat = table.insert, table.concat; 29 local t_insert, t_concat = table.insert, table.concat;
30 local type = type; 30 local type = type;
31 local next = next; 31 local next = next;
32 local rawget = rawget; 32 local rawget = rawget;
33 33 local error = error;
34 local tostring = tostring; 34 local tostring = tostring;
35 35
36 -- We need this to let modules access the real global namespace 36 -- We need this to let modules access the real global namespace
37 local _G = _G; 37 local _G = _G;
38 38
398 return; 398 return;
399 end 399 end
400 return api.hook(self, "stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end, priority); 400 return api.hook(self, "stanza/"..(xmlns and (xmlns..":") or "")..name, function (data) return handler(data.origin, data.stanza, data); end, priority);
401 end 401 end
402 402
403 function api:require(lib)
404 local f, n = pluginloader.load_code(self.name, lib..".lib.lua");
405 if not f then
406 f, n = pluginloader.load_code(lib, lib..".lib.lua");
407 end
408 if not f then error("Failed to load plugin library '"..lib.."', error: "..n); end -- FIXME better error message
409 return f();
410 end
411
403 -------------------------------------------------------------------- 412 --------------------------------------------------------------------
404 413
405 local actions = {}; 414 local actions = {};
406 415
407 function actions.load(params) 416 function actions.load(params)