[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaWebserver [was: a few questions re LuaSockets]
- From: Joe Stewart <jstewart@...>
- Date: Mon, 27 Jan 2003 10:31:44 -0800
At 09:58 PM 1/23/2003, you wrote:
>I was wondering if it was possible from standard lua to set the global
>environment to another table prior to a dofile(), then kill the temp one
>and restore the main?
Sure. In Lua 4 do
do
local newG={ fill here with what is needed in the sandbox }
local oldG=globals(newG)
oldG.dofile(xxx)
oldG.globals(oldG)
end
Thanks for the tip... I had problems with this at first until I realized I
had to put all the functions I wanted to use into the new environment like:
do
local newG = {}
newG.write = write
newG._OUTPUT = write
newG._ERRORMESSAGE = _ERRORMESSAGE
newG._ALERT = _ALERT
local oldG = globals(newG)
oldG.dofile(xxx)
oldG.globals(oldG)
end
seeing error messages helped a great deal ;-)!
On a side note, I'm a forth fan from waaaaay back. Lua reminds me (in the
most positive aspects) of forth with a contemporary syntax. Anyone else
have this background and care to comment? I was most amused with the
ability to redefine existing functions... very nice!
Thanks to the lua creators and community! I really like lua!
-joe