[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Environments
- From: "Alex Queiroz" <asandroq@...>
- Date: Wed, 21 Mar 2007 13:50:09 -0300
Hallo,
On 3/21/07, Eva Schmidt <es@sol-3.de> wrote:
I want to execute a little script from another script using loadfile(). Because
of the fact that I cannot make sure that this script doesn't contain code I
don't want to be executed (like os.exit() or something) I tried to just allow
certain functions using an environment like that:
-- create local environment for loadstring()
local fenv = {}
fenv.print = _G.print
setfenv (loadstring, fenv)
result, error = loadstring (s)
With this environment it should be possible to just call the printing function
within the chunk to be loaded. Maybe this approach is too naive - Lua forbits
changing the environment for the function loadstring() ;-(
You are changing the environment of the loadstring function. You
should change the environment of the loaded function:
result = setfenv(result, fenv)
Cheers,
--
-alex
http://www.ventonegro.org/