Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function with(scope)
- local cEnv = {}
- local oEnv = getfenv(2)
- local cEnvMT = {}
- local outT = {}
- local outMT = {}
- outMT.__index = function(t,k)
- return oEnv[k]
- end
- outMT.__newindex = function(t,k,v)
- oEnv[k]=v
- end
- outMT.__call = function(...)
- setfenv(2,oEnv)
- oEnv = nil
- end
- setmetatable(outT,outMT)
- cEnvMT.__index = function(t,k)
- if k == "out" then
- return outT
- else
- return scope[k] or outT[k]
- end
- end
- cEnvMT.__newindex = function(t,k,v)
- scope[k]=v
- end
- setmetatable(cEnv,cEnvMT)
- setfenv(2,cEnv)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement