# HG changeset patch # User Matthew Wild # Date 1256138749 -3600 # Node ID 545c0d6b6bb3c6dc0632d53886986e4d05ec1bf4 # Parent 4ab83f96585a43d5eeac5a97dfcbdd4f47a77202 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 :) diff -r 4ab83f96585a -r 545c0d6b6bb3 prosody --- a/prosody Wed Oct 21 19:01:02 2009 +0500 +++ b/prosody Wed Oct 21 16:25:49 2009 +0100 @@ -32,7 +32,26 @@ -- 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"