modulemanager: Set module.environment before calling add_host, otherwise the module will get the parent's environment (thanks xnyhps and Maranda)
authorMatthew Wild <mwild1@gmail.com>
Fri, 27 Apr 2012 21:37:45 +0100
changeset 4728 7c81b04a4fed
parent 4727 5ebf4096a2e1
child 4729 da3c1d980c04
modulemanager: Set module.environment before calling add_host, otherwise the module will get the parent's environment (thanks xnyhps and Maranda)
core/modulemanager.lua
--- a/core/modulemanager.lua	Fri Apr 27 20:01:21 2012 +0100
+++ b/core/modulemanager.lua	Fri Apr 27 21:37:45 2012 +0100
@@ -142,10 +142,10 @@
 			},{
 				__index = modulemap["*"][module_name].module;
 			});
+			local host_module = setmetatable({ module = host_module_api }, { __index = mod });
+			host_module_api.environment = host_module;
 			local ok, result, module_err = call_module_method(mod, "add_host", host_module_api);
 			if not ok or result == false then return nil, ok and module_err or result; end
-			local host_module = setmetatable({ module = host_module_api }, { __index = mod });
-			host_module.module.environment = host_module;
 			modulemap[host][module_name] = host_module;
 			return host_module;
 		end