lua-users home
lua-l archive

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


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 :/