[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: "import"?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 02 Oct 2000 10:49:25 -0200
> This appears to require 4.0, no?
Yes.
> I should have put the extra requirement that I need this in 3.2.
You can do something similar, but instead of changing the table of globals,
you will have to copy all globals to a new table, and then erase all globals.
It will be slower, but I think it works:
-- save these functions, as they will be erased from global space
local foreach, foreachvar, setglobal = foreach, foreachvar, setglobal
local oldstate = {}
-- save current globals
foreachvar(function(n,v) %oldstate[n] = v end)
foreachvar(function(n) %setglobal(n, nil) end) -- erase all globals
... -- set tag method and dofile as before
local newstate = {}
-- save new globals in this state
foreachvar(function(n,v) %oldstate[n] = v end)
foreachvar(function(n) %setglobal(n, nil) end) -- erase new globals
-- restore old globals
foreach(oldstate, function(n,v) %setglobal(n,v) end)
-- Roberto