aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-02-24 19:26:26 +0100
committerJokler <jokler.contact@gmail.com>2018-02-24 19:26:26 +0100
commitf24da1f5090d71a4963e05c5a76dad2eccac15bd (patch)
tree1a8212eed07ba1bff2ac3077ecf0e7e03da57920 /src
parent886bd6d4d77a941946bec0d7f8b5c422d206feea (diff)
downloadfrippy-f24da1f5090d71a4963e05c5a76dad2eccac15bd.tar.gz
frippy-f24da1f5090d71a4963e05c5a76dad2eccac15bd.zip
Add temporary eval function to factoids
Diffstat (limited to 'src')
-rw-r--r--src/plugins/factoids/sandbox.lua27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/plugins/factoids/sandbox.lua b/src/plugins/factoids/sandbox.lua
index 31ef5cb..3fc74cd 100644
--- a/src/plugins/factoids/sandbox.lua
+++ b/src/plugins/factoids/sandbox.lua
@@ -16,6 +16,7 @@ end
local sandbox_env = {
print = send,
println = sendln,
+ eval = nil,
args = args,
input = input,
user = user,
@@ -49,18 +50,30 @@ sandbox_env.string.rep = nil
sandbox_env.string.dump = nil
sandbox_env.math.randomseed = nil
-local f, e = load(factoid, nil, nil, sandbox_env)
+-- Temporary evaluation function
+function eval(code)
+ local c, e = load(code, nil, nil, sandbox_env)
+ if c then
+ return c()
+ else
+ error(e)
+ end
+end
+
+sandbox_env.eval = eval
-- Check if the factoid timed out
function checktime(event, line)
- if os.time() - time >= timeout then
- error("Timed out after " .. timeout .. " seconds", 0)
- else
- -- Limit the cpu usage of factoids
- sleep(1)
- end
+ if os.time() - time >= timeout then
+ error("Timed out after " .. timeout .. " seconds", 0)
+ else
+ -- Limit the cpu usage of factoids
+ sleep(1)
+ end
end
+local f, e = load(factoid, nil, nil, sandbox_env)
+
-- Add timeout hook
time = os.time()
timeout = 30