VEnv
VEnv
Lua Virtual Environment
overview · download · news · reference · examples

Contents

Overview

Lua Virtual Environment is a simple library which provides a way to execute a Lua function in a separate environment, protecting the original one.

VEnv is free software and uses the same license as Lua 5.0.

Current version

Current version is 1.0. It was developed for Lua 5.0 and Lua 5.1.

Download

VEnv can be downloaded from its LuaForge page.

What's new

VEnv 1.0 follows the package proposal for Lua 5.1, therefore this package should be "installed". In other words, if you are using Lua 5.0, the file compat-5.1.lua must be installed in the LUA_PATH. If you are using Lua 5.1, nothing should be done.

Reference

VEnv provides a single function to do its job:

Examples

Suppose the file script.lua is as follows:

x = "inside"
assert((x == "inside"), "error setting/accessing variable x inside VEnv", x)
assert((os.execute == nil), "os.execute should not be allowed")
var = 1

And here is the main chunk which will execute the above script inside a Virtual Environment.

require"venv"
t1 = { t2 = { t3 = "ok" } }
x = "outside"

function sb ()
    assert ((t1.t2.t3 == "ok"), "error accessing multi-indexed variable")
    os.execute = nil
    loadfile ("script.lua")()
end

local prot = venv (sb)
prot ()
assert ((x == "outside"), "variable x modified by VEnv!")
assert ((var == nil), "VEnv modified external environment!")
assert ((os.execute ~= nil), "VEnv modified external environment!")

Credits

VEnv was designed by Roberto Ierusalimschy, Ana Lúcia de Moura, André Carregal and Tomás Guisasola as part of The Kepler Project which holds its copyright. It was implemented by Ana Lúcia de Moura.

Contact us

For more information please contact us. Comments are welcome!


$Id: index.html,v 1.5 2004/11/11 13:39:57 tomas Exp $