aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-10-21 16:25:49 +0100
committerMatthew Wild <mwild1@gmail.com>2009-10-21 16:25:49 +0100
commitb91a6de8cfce62ee088d13322bb92de262c38dce (patch)
tree140526352e77032d49632358214f9afe21417ae7
parent9f001523b27f094d292cf33fb14be6b1df5feba9 (diff)
downloadprosody-b91a6de8cfce62ee088d13322bb92de262c38dce.tar.gz
prosody-b91a6de8cfce62ee088d13322bb92de262c38dce.zip
prosody, util.require: Remove util.require, the shortest-lived module so far. Woke up this morning with a much simpler idea, which is also effective against C modules (I believe). Yay for metatables :)
-rwxr-xr-xprosody21
1 files changed, 20 insertions, 1 deletions
diff --git a/prosody b/prosody
index 2c0c5784..99d7602c 100755
--- a/prosody
+++ b/prosody
@@ -32,7 +32,26 @@ end
-- Required to be able to find packages installed with luarocks
pcall(require, "luarocks.require")
-require "util.require";
+
+-- Replace require with one that doesn't pollute _G
+do
+ local _realG = _G;
+ local _real_require = require;
+ function require(...)
+ local curr_env = getfenv(2);
+ local curr_env_mt = getmetatable(getfenv(2));
+ local _realG_mt = getmetatable(_realG);
+ if curr_env_mt and curr_env_mt.__index and not curr_env_mt.__newindex and _realG_mt then
+ local old_newindex
+ old_newindex, _realG_mt.__newindex = _realG_mt.__newindex, curr_env;
+ local ret = _real_require(...);
+ _realG_mt.__newindex = old_newindex;
+ return ret;
+ end
+ return _real_require(...);
+ end
+end
+
config = require "core.configmanager"