[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Controlling scoping
- From: Peter Hickman <peterhi@...>
- Date: Tue, 30 Mar 2004 09:37:11 +0100
Kevin Baca wrote:
See setfenv() in the lua docs
http://www.lua.org/manual/5.0/manual.html#5.1
Thanks for the pointer, I now have
[Lua]$ cat example.lua
#!/usr/local/bin/lua
function mycall( f )
local _g = getfenv(1)
f()
setfenv(1, _g)
end
s1 = "x = 42"
s2 = "print(x)"
c1 = loadstring(s1)
c2 = loadstring(s2)
mycall( c2 )
mycall( c1 )
mycall( c2 )
[Lua]$
Which seems to work, at least for the example.
Onward and upward