|
Specifically, why does this not work: id = 0 env1 = { id = 1, __index = _G } setmetatable(env1, env1) function subtest() print("subtest", id) b = id end function test() print("test", id) subtest() a = id end test() setfenv(0, env1) -- change global environment test() -- environment in test & subtest remains unchanged output: test 0 subtest 0 test 0 subtest 0 What I want is some way to change the environment of ALL existing and future functions that do not have a specific environment already set. Perhaps I need to have a 'virtual' environment at the root, whose __index and __newindex can be remapped dynamically? This is only speculative, it might not be a good idea at all, but I'm looking ahead to coroutines as a way to be able to switch system data state quickly and independently of system functional behavior, and it seemed (until I noticed this) that environments would be a good way to do it. On Mar 24, 2007, at 3:23 PM, Graham Wakefield wrote:
Grrr Waaa www.grahamwakefield.net |