lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

I'm trying to solve a problem with require (and the loaders it uses)
using the Thread's environment when I would rather it use the main
state's environment (the true global environment). Is there a cleaner
way to solve this than hooking the require function which temporarily
changes the thread environment to the main thread environment?

Something like (in Lua and untested):

do
  local req = require;
  local main_env = getfenv(0);
  function require(...)
    local env = getfenv(0);
    setfenv(0, main_env);
    local ret = req(...);
    setfenv(0, env);
    return ret;
  end
end

Thanks for any help,

-- 
-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant