diff options
| author | Jokler <jokler.contact@gmail.com> | 2018-02-24 19:26:26 +0100 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2018-02-24 19:26:26 +0100 |
| commit | f24da1f5090d71a4963e05c5a76dad2eccac15bd (patch) | |
| tree | 1a8212eed07ba1bff2ac3077ecf0e7e03da57920 /src/plugins/factoids/sandbox.lua | |
| parent | 886bd6d4d77a941946bec0d7f8b5c422d206feea (diff) | |
| download | frippy-f24da1f5090d71a4963e05c5a76dad2eccac15bd.tar.gz frippy-f24da1f5090d71a4963e05c5a76dad2eccac15bd.zip | |
Add temporary eval function to factoids
Diffstat (limited to 'src/plugins/factoids/sandbox.lua')
| -rw-r--r-- | src/plugins/factoids/sandbox.lua | 27 |
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 |
