[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: "import"?
- From: "Michael T. Richter" <mtr@...>
- Date: Sun, 1 Oct 2000 11:23:42 -0400
> local newenv = {}
> local oldenv = globals()
> local oldtm = gettagmethod(tag(nil), 'getglobal)
> settagmethod(tag(nil), 'getglobal', function (varname)
> return %oldenv[varname]
> end) -- alow new environment to use all variables from old one
> globals(newenv) -- set new environment
> dofile(filename)
> globals(oldenv) -- restore environment
> settagmethod(tag(nil), 'getglobal', oldtm)
> return newenv
That's brilliant, Roberto!
Every time I think "now here's something that Lua probably can't do well" I
seem to be proven wrong. With a couple of very minor tweaks the code you've
written can be turned into a full-fledged Lua module system.