If you using the environment control, you don't need to change the _G back at the end, and you won't write anything to the _G since your job is done in the private environment.
http://www.wowinterface.com/forums/s...5&postcount=11
With the environment control, we'll have more power with our codes, here is an example:
Lua Code:
if val = ture then print("val is true") end
The "ture" is a spell error for 'true', and it'd be treated as nil, the code would run and we won't know the bug. With the environment control :
Lua Code:
-- Modify the environment, using private table as environment
setfenv(1, setmetatable( select(2, ...), { __index = function(self, key)
local val = _G[key]
if val ~= nil then rawset(self, key, val) else error(("Global variable %q can't be found"):format(key), 2) end
return val
end } ))
local a = true
if a == ture then print("Okay") end -- error Global variable "ture" can't be found
I also development plenty features based on it :
http://www.wowinterface.com/forums/s...ad.php?t=55057