lua-users home
lua-l archive

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


2010/1/7 Petite Abeille <petite.abeille@gmail.com>:
>
> On Jan 7, 2010, at 6:56 PM, Leo Razoumov wrote:
>
>> What would be Lua-5.2 idioms for creating sandboxes and jails?
>
> Perhaps something along these lines?
>
> function Sandbox( anEnvironment, aFunction, ... )
>  in anEnvironment do
>    aFunction( ... )
>  end
> end
>
> function Test( anIndex )
>  print( anIndex, _VERSION )
> end
>
> Sandbox( {}, Test, 1 )
> Sandbox( _G, Test, 2 )
>
>> 1, nil
>> 2, Lua 5.2
>
> Just idle speculation though. Need to get used to the idea of loosing get/setfenv first :/

I thought "in" was lexical, so that the names in Test would *not* be
looked up in anEnvironment. You seem to be assuming that "in" uses
dynamic scope.

Paul.