[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Require function and threads with different environments
- From: "Patrick Donnelly" <batrick.donnelly@...>
- Date: Tue, 10 Jun 2008 20:19:18 -0600
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