[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Environments
- From: Eike Decker <eike@...>
- Date: Thu, 22 Mar 2007 00:23:49 +0100
Just be aware that some functions will set a new environment table for a
function. I.e. loadstring, dofile, loadfile and require will all set the
function environment to normal, which will break your sandbox system. You will
have to provide modified functions of that type if you want to allow people to
load other lua files as well without allowing them to access the global
functions.
Eike
> That's it! Thanks a lot!
>
> Bye Eva
>
> Alex Queiroz wrote:
> > 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,
>
> --
>
> --
>
> \ / Sol-3 GmbH & Co. KG Eva Schmidt
> --o-- Sol-3 Eltviller Straße 2 Phone: ++49 (0) 6123 7029
> 23
> / \ D-65399 Kiedrich Fax: ++49 (0) 6123 7029
> 29
> USt-ID: DE 204978307 eMail: es@sol-3.de
> Register: WI HRA 6607
> Komplementär: Sol-3 Verwaltungs GmbH
> Register: WI HRB 117786
> Geschäftsführer: Norbert Geus, Dirk Zoller
>
>
- References:
- Re: Use of Lua corotines in games, Steven Johnson
- What's wrong here?, Thomas Lauer
- Re: What's wrong here?, Kristofer Karlsson
- Re: What's wrong here?, Julien Hamaide
- Lua 5.1.1 LOADNIL optimization bug (was: What's wrong here?), Mike Pall
- Re: Lua 5.1.1 LOADNIL optimization bug, Julien Hamaide
- Re: Lua 5.1.1 LOADNIL optimization bug, Mike Pall
- Environments, Eva Schmidt
- Re: Environments, Alex Queiroz
- Re: Environments, Eva Schmidt