core/modulemanager.lua

changeset 747
40837f3422ab
parent 746
7027de4c039d
child 748
172c43d735e9
equal deleted inserted replaced
746:7027de4c039d 747:40837f3422ab
27 local eventmanager = require "core.eventmanager"; 27 local eventmanager = require "core.eventmanager";
28 local config = require "core.configmanager"; 28 local config = require "core.configmanager";
29 local multitable_new = require "util.multitable".new; 29 local multitable_new = require "util.multitable".new;
30 local register_actions = require "core.actions".register; 30 local register_actions = require "core.actions".register;
31 31
32 local hosts = hosts;
33
32 local loadfile, pcall = loadfile, pcall; 34 local loadfile, pcall = loadfile, pcall;
33 local setmetatable, setfenv, getfenv = setmetatable, setfenv, getfenv; 35 local setmetatable, setfenv, getfenv = setmetatable, setfenv, getfenv;
34 local pairs, ipairs = pairs, ipairs; 36 local pairs, ipairs = pairs, ipairs;
35 local t_insert, t_concat = table.insert, table.concat; 37 local t_insert, t_concat = table.insert, table.concat;
36 local type = type; 38 local type = type;
229 231
230 function module_has_method(module, method) 232 function module_has_method(module, method)
231 return type(module.module[method]) == "function"; 233 return type(module.module[method]) == "function";
232 end 234 end
233 235
234 function call_module_method(module, func, ...) 236 function call_module_method(module, method, ...)
235 local f = module.module[func];
236 if module_has_method(module, method) then 237 if module_has_method(module, method) then
238 local f = module.module[func];
237 return pcall(f, ...); 239 return pcall(f, ...);
238 else 240 else
239 return false, "no-such-method"; 241 return false, "no-such-method";
240 end 242 end
241 end 243 end
255 end 257 end
256 258
257 -- Returns the host that the current module is serving 259 -- Returns the host that the current module is serving
258 function api:get_host() 260 function api:get_host()
259 return self.host; 261 return self.host;
262 end
263
264 function api:get_host_type()
265 return hosts[self.host].type;
260 end 266 end
261 267
262 function api:set_global() 268 function api:set_global()
263 self.host = "*"; 269 self.host = "*";
264 end 270 end

mercurial