improve $eval
This commit is contained in:
parent
e0b8fe3c86
commit
25a335f5a4
1 changed files with 26 additions and 3 deletions
29
irc.lamb
29
irc.lamb
|
@ -21,6 +21,30 @@ EVAL_ENV = [("id", id),
|
||||||
("locals", locals),
|
("locals", locals),
|
||||||
("list", list)].
|
("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.
|
fst((x, _)) -> x.
|
||||||
|
|
||||||
-- maybe stuff
|
-- maybe stuff
|
||||||
|
@ -113,7 +137,7 @@ say(chan, msg) -> fputstr(sock, "PRIVMSG " + chan + " :" + msg + "\r\n").
|
||||||
|
|
||||||
handleMessage(s, nick, chan, "$factoids") -> do
|
handleMessage(s, nick, chan, "$factoids") -> do
|
||||||
factoids = list\map(fst, getFactoids(s));
|
factoids = list\map(fst, getFactoids(s));
|
||||||
say(chan, nick + ": " + repr(factoids));
|
say(chan, nick + ": " + list\intercalate(" ", factoids));
|
||||||
s
|
s
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -134,8 +158,7 @@ handleMessage(s, nick, chan, "$savefacts") -> do
|
||||||
end.
|
end.
|
||||||
|
|
||||||
handleMessage(s, nick, chan, "$eval "::line) -> do
|
handleMessage(s, nick, chan, "$eval "::line) -> do
|
||||||
ret = eval(line, EVAL_ENV);
|
irc_eval(line, chan, nick);
|
||||||
say(chan, nick + ": " + repr(ret));
|
|
||||||
s
|
s
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue