Software /
code /
prosody
Comparison
core/modulemanager.lua @ 4728:7c81b04a4fed
modulemanager: Set module.environment before calling add_host, otherwise the module will get the parent's environment (thanks xnyhps and Maranda)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 27 Apr 2012 21:37:45 +0100 |
parent | 4665:6be91ca54613 |
child | 4733:791388f90156 |
comparison
equal
deleted
inserted
replaced
4727:5ebf4096a2e1 | 4728:7c81b04a4fed |
---|---|
140 host = host, event_handlers = {}, items = {}; | 140 host = host, event_handlers = {}, items = {}; |
141 _log = _log, log = function (self, ...) return _log(...); end; | 141 _log = _log, log = function (self, ...) return _log(...); end; |
142 },{ | 142 },{ |
143 __index = modulemap["*"][module_name].module; | 143 __index = modulemap["*"][module_name].module; |
144 }); | 144 }); |
145 local host_module = setmetatable({ module = host_module_api }, { __index = mod }); | |
146 host_module_api.environment = host_module; | |
145 local ok, result, module_err = call_module_method(mod, "add_host", host_module_api); | 147 local ok, result, module_err = call_module_method(mod, "add_host", host_module_api); |
146 if not ok or result == false then return nil, ok and module_err or result; end | 148 if not ok or result == false then return nil, ok and module_err or result; end |
147 local host_module = setmetatable({ module = host_module_api }, { __index = mod }); | |
148 host_module.module.environment = host_module; | |
149 modulemap[host][module_name] = host_module; | 149 modulemap[host][module_name] = host_module; |
150 return host_module; | 150 return host_module; |
151 end | 151 end |
152 return nil, "global-module-already-loaded"; | 152 return nil, "global-module-already-loaded"; |
153 end | 153 end |