Software / code / prosody
Comparison
core/modulemanager.lua @ 4641:2b3ee52fba32
modulemanager: Make module_has_method and module_call_method use rawget()
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 21 Apr 2012 20:04:07 +0100 |
| parent | 4640:645c93eaf249 |
| child | 4642:c1602c07d14d |
comparison
equal
deleted
inserted
replaced
| 4640:645c93eaf249 | 4641:2b3ee52fba32 |
|---|---|
| 259 function is_loaded(host, name) | 259 function is_loaded(host, name) |
| 260 return modulemap[host] and modulemap[host][name] and true; | 260 return modulemap[host] and modulemap[host][name] and true; |
| 261 end | 261 end |
| 262 | 262 |
| 263 function module_has_method(module, method) | 263 function module_has_method(module, method) |
| 264 return type(module.module[method]) == "function"; | 264 return type(rawget(module.module, method)) == "function"; |
| 265 end | 265 end |
| 266 | 266 |
| 267 function call_module_method(module, method, ...) | 267 function call_module_method(module, method, ...) |
| 268 if module_has_method(module, method) then | 268 local f = rawget(module.module, method); |
| 269 local f = module.module[method]; | 269 if type(f) == "function" then |
| 270 return pcall(f, ...); | 270 return pcall(f, ...); |
| 271 else | 271 else |
| 272 return false, "no-such-method"; | 272 return false, "no-such-method"; |
| 273 end | 273 end |
| 274 end | 274 end |