lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

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
print(vars.i, vars.r1, vars.r2)

Renato Maia
Computer Scientist