Software /
code /
prosody
Comparison
core/modulemanager.lua @ 747:40837f3422ab
modulemanager: Add get_host_type() API method, and fix up call_module_method to work properly
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 29 Jan 2009 01:58:11 +0000 |
parent | 746:7027de4c039d |
child | 748:172c43d735e9 |
comparison
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 |