Isolation help you to create a isolated lua environment, a sandbox.
It's easy to create an new environment and run code inside.
It's harder to have a full emulated require
and package management inside this sandbox.
Isolation allow you to create a new isolated package management (including require).
I decide to follow :
- the Lua 5.2 (5.3?)
require
implementation, it means arequire
without sentinel. - the package table items follow the Lua 5.3 names, with the
package.loaders
==package.searchers
and thepaackage.searchpath
is implemented. - the new created environment does only contains
table
andstring
. All other module must be called with therequire
function.
You are also able to make a new require
attached to the current package
table.
The isolation's require
follow the Lua5.2+ one.
It should be usefull to got a modern require
on Lua 5.1.
- Inception : Be able to load this module inside a isolated environment create a new one.
- API : define the minimal function to setup a isolated environment
- Customization : find a good way to setup what you want
- Sharing : how manage/control sharing stuff between guest and parent environment
- ... and more.
Tested with Lua 5.1, LuaJIT(5.1), Lua5.2. Should be compatible with Lua 5.3.
With new
inspired from rings.new(env)
local inst = require "isolation".new()
Inspired from slave:dostring(string_luacode, ...)
dostring
is like pcall
.
local ok, res = inst:dostring("return 123")
assert(ok == true and res == 123)
local ok, res1, res2 = inst:dostring("return 123, '456'")
assert(ok == true and res1 == 123 and res2 == "456")
Inspired from sandbox.run
For now I have issue with run fnd unction.
The current run
support string.
local result = inst:run("return 123")
assert(result == 123)
local slave_require = inst:run("return require")
assert(slave_require"os".exit == nil)
For now I have issue with run function.
I make a runf
for running function
local result = inst:runf(function() return 123 end)
assert(result == 123)
Similar projet
About potential futur API :
- rings that has master/slave API.
Licensed under MIT.