improve $eval

This commit is contained in:
darkf 2015-02-13 04:10:47 -08:00
parent e0b8fe3c86
commit 25a335f5a4
1 changed files with 26 additions and 3 deletions

View File

@ -21,6 +21,30 @@ EVAL_ENV = [("id", id),
("locals", locals),
("list", list)].
irc_eval(code, chan, nick) -> do
eval_watchdog = \_ -> do
value = ref!(false);
f = \_ -> do
ret = eval(code, EVAL_ENV);
setRef!(value, (ret,))
end;
thread = thread!(f);
sleep!(3000); -- wait 3 seconds
val = readRef!(value);
if val == false then do
kill!(thread);
say(chan, nick + ": time limit exceeded")
end
else do
(ret,) = val;
say(chan, nick + ": " + repr(ret))
end
end;
thread!(eval_watchdog)
end.
fst((x, _)) -> x.
-- maybe stuff
@ -113,7 +137,7 @@ say(chan, msg) -> fputstr(sock, "PRIVMSG " + chan + " :" + msg + "\r\n").
handleMessage(s, nick, chan, "$factoids") -> do
factoids = list\map(fst, getFactoids(s));
say(chan, nick + ": " + repr(factoids));
say(chan, nick + ": " + list\intercalate(" ", factoids));
s
end.
@ -134,8 +158,7 @@ handleMessage(s, nick, chan, "$savefacts") -> do
end.
handleMessage(s, nick, chan, "$eval "::line) -> do
ret = eval(line, EVAL_ENV);
say(chan, nick + ": " + repr(ret));
irc_eval(line, chan, nick);
s
end.