lua-users home
lua-l archive

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


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