lua-users home
lua-l archive

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


On Tue, 12 Jan 2010, Enrico Colombini wrote:
> Tony Finch wrote:
> >   local t = {}
> >   local s = "function f() a = 3 print(a) end"
> >   local chunk = assert(loadstring("in ... do "..s.." end"))
> >   chunk(t)
>
> Besides, it could be convenient to be able to execute a chunk in different
> environments without reloading it.

If you load the chunk as above then you can just do

  chunk(env1)
  chunk(env2)

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.