mirror of
https://github.com/kikito/lua-sandbox.git
synced 2024-12-18 03:04:20 +00:00
feat(sandbox) return multiple values
This commit is contained in:
parent
11ee23ae30
commit
67728e9ea4
@ -166,12 +166,13 @@ function sandbox.protect(f, options)
|
||||
|
||||
string.rep = nil
|
||||
|
||||
local ok, result = pcall(f, ...)
|
||||
local t = table.pack(pcall(f, ...))
|
||||
|
||||
cleanup()
|
||||
|
||||
if not ok then error(result) end
|
||||
return result
|
||||
if not t[1] then error(t[2]) end
|
||||
|
||||
return table.unpack(t, 2, t.n)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -34,6 +34,11 @@ describe('sandbox.run', function()
|
||||
assert.error(function() sandbox.run('return setmetatable({}, {})') end)
|
||||
assert.error(function() sandbox.run('return string.rep("hello", 5)') end)
|
||||
end)
|
||||
|
||||
it('does return multiple values', function()
|
||||
local result = { sandbox.run("return 'hello', 'world'") }
|
||||
assert.same({ 'hello', 'world' }, result)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('when handling string.rep', function()
|
||||
|
Loading…
Reference in New Issue
Block a user