[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua registry, environment, and threads.
- From: Tony Finch <dot@...>
- Date: Tue, 12 Jan 2010 12:07:35 +0000
On Tue, 12 Jan 2010, Juris Kalnins wrote:
>
> do a=1
> do dynamic a=2
> g() -- access to a gives 2
> end -- a == 1
> end
>
> where 'dynamic' is like 'local' in perl :)
function dynamic(t,f)
local save = {}
for k,v in pairs(t) do
save[k] = _G[k]
_G[k] = v
end
f()
for k in pairs(t) do
_G[k] = save[k]
end
end
do a=1
dynamic({ a=2 },function()
g() -- access to a gives 2
end)
-- a == 1
end
If there were hooks on the environment of 5.2 "in" blocks so that the code
knows when the block is finished, you could perhaps write something like
do a=1
in dynamic{ a=2 } do
g() -- access to a gives 2
end
-- a == 1
end
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.
- References:
- Re: Lua registry, environment, and threads., Christian Tellefsen
- Re: Lua registry, environment, and threads., Roberto Ierusalimschy
- Re: Lua registry, environment, and threads., Mark Hamburg
- Re: Lua registry, environment, and threads., Patrick Donnelly
- Re: Lua registry, environment, and threads., Roberto Ierusalimschy
- Re: Lua registry, environment, and threads., Leo Razoumov
- Re: Lua registry, environment, and threads., Petite Abeille
- Re: Lua registry, environment, and threads., Paul Moore
- Re: Lua registry, environment, and threads., Petite Abeille
- Re: Lua registry, environment, and threads., Juris Kalnins
- Re: Lua registry, environment, and threads., Sean Conner
- Re: Lua registry, environment, and threads., Juris Kalnins
- Re: Lua registry, environment, and threads., Juris Kalnins