From 48ae2844e98e77845bb03fdb249d01e23d9e7762 Mon Sep 17 00:00:00 2001 From: kikito Date: Sat, 14 Sep 2013 12:49:46 +0200 Subject: [PATCH] made sandbox survive if debug lib is not present --- sandbox.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sandbox.lua b/sandbox.lua index c3317ba..ff0a8d4 100644 --- a/sandbox.lua +++ b/sandbox.lua @@ -104,8 +104,13 @@ local function merge(dest, source) return dest 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() - debug.sethook() + sethook() string.rep = string_rep end @@ -127,7 +132,7 @@ function sandbox.protect(f, options) error('Quota exceeded: ' .. tostring(quota)) end - debug.sethook(timeout, "", quota) + sethook(timeout, "", quota) string.rep = nil local ok, result = pcall(f, ...)