mirror of
https://github.com/kikito/lua-sandbox.git
synced 2024-12-18 03:04:20 +00:00
made sandbox survive if debug lib is not present
This commit is contained in:
parent
66a82c06ce
commit
48ae2844e9
@ -104,8 +104,13 @@ local function merge(dest, source)
|
|||||||
return dest
|
return dest
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function sethook(f, key, quota)
|
||||||
|
if type(debug) ~= 'table' or type(debug.sethook) ~= 'function' then return end
|
||||||
|
debug.sethook(f, key, quota)
|
||||||
|
end
|
||||||
|
|
||||||
local function cleanup()
|
local function cleanup()
|
||||||
debug.sethook()
|
sethook()
|
||||||
string.rep = string_rep
|
string.rep = string_rep
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -127,7 +132,7 @@ function sandbox.protect(f, options)
|
|||||||
error('Quota exceeded: ' .. tostring(quota))
|
error('Quota exceeded: ' .. tostring(quota))
|
||||||
end
|
end
|
||||||
|
|
||||||
debug.sethook(timeout, "", quota)
|
sethook(timeout, "", quota)
|
||||||
string.rep = nil
|
string.rep = nil
|
||||||
|
|
||||||
local ok, result = pcall(f, ...)
|
local ok, result = pcall(f, ...)
|
||||||
|
Loading…
Reference in New Issue
Block a user