[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: setfenv/getfenv
- From: Renato Maia <maia@...>
- Date: Tue, 12 Jan 2010 15:36:25 -0200
On 12 Jan 2010, at 14:09, Alexander Gladysh wrote:
This approach is not compatible with the case when "code" is in
bytecode form.
You can also use a proxy table to dynamically change the environment
of functions you load/create:
local meta = {}
local env = setmetatable({}, meta)
local f1, f2
f1 = loadin(env, "r1=i+1")
in env do function f2() r2=i+2 end end
local vars = {i=1}
meta.__index = vars
meta.__newindex = vars
f1()
f2()
print(vars.i, vars.r1, vars.r2)
--
Renato Maia
Computer Scientist
Tecgraf/PUC-Rio
__________________________
http://www.inf.puc-rio.br/~maia/