lua-users home
lua-l archive

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

Kevin Baca wrote:

See setfenv() in the lua docs
Thanks for the pointer, I now have

[Lua]$ cat example.lua

function mycall( f )
       local _g = getfenv(1)
       setfenv(1, _g)

s1 = "x = 42"
s2 = "print(x)"

c1 = loadstring(s1)
c2 = loadstring(s2)

mycall( c2 )
mycall( c1 )
mycall( c2 )

Which seems to work, at least for the example.

Onward and upward