![]() |
VEnv |
Lua Virtual Environment |
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 is 1.0. It was developed for Lua 5.0 and Lua 5.1.
VEnv can be downloaded from its LuaForge page.
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.
VEnv provides a single function to do its job:
venv (func) => function
venv
returns
the new virtual environment created.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!")
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.
For more information please contact us. Comments are welcome!