-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStdLib.cpp
45 lines (37 loc) · 1.04 KB
/
StdLib.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "StdLib.h"
#include "PPrint.h"
#include <QEventLoop>
#include <QTimer>
StdLib::StdLib()
{
_print.addNativeSentence("e.Expr", [](VarContext args)
{
auto expr = args.expressionVar("Expr");
sout(pprint(args.expressionVar("Expr")));
return expr;
});
_prout.addNativeSentence("e.Expr", [](VarContext args)
{
auto expr = args.expressionVar("Expr");
sout(pprint(expr));
return QList<Token>();
});
_sleep.addNativeSentence("s.Time", [](VarContext args)
{
Token time = args.singleVar("Time");
if (time.type() != Token::INTEGER)
rtError("Invalid argument", "First argument to <Time> must be an integer, got " + pprint(time));
QEventLoop loop;
QTimer timer;
timer.connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
timer.start(time.integer());
loop.exec();
return QList<Token>();
});
}
void StdLib::load(Evaluator &eval)
{
eval.addFunction(_print);
eval.addFunction(_prout);
eval.addFunction(_sleep);
}