blob: be91d5962254e251eeb3edddad6ffffcdb8ad6eb [file] [log] [blame]
swissChili323883d2022-02-20 16:35:23 -08001#include "StdLib.h"
2#include "PPrint.h"
3
swissChili5d3e5562022-02-24 16:49:19 -08004#include <QEventLoop>
5#include <QTimer>
6
swissChili323883d2022-02-20 16:35:23 -08007StdLib::StdLib()
8{
swissChili918557c2022-02-20 20:16:34 -08009 _print.addNativeSentence("e.Expr", [](VarContext args)
swissChili323883d2022-02-20 16:35:23 -080010 {
swissChili918557c2022-02-20 20:16:34 -080011 auto expr = args.expressionVar("Expr");
12 sout(pprint(args.expressionVar("Expr")));
13 return expr;
swissChili323883d2022-02-20 16:35:23 -080014 });
15
swissChili918557c2022-02-20 20:16:34 -080016 _prout.addNativeSentence("e.Expr", [](VarContext args)
swissChili323883d2022-02-20 16:35:23 -080017 {
swissChili918557c2022-02-20 20:16:34 -080018 auto expr = args.expressionVar("Expr");
19 sout(pprint(expr));
swissChili323883d2022-02-20 16:35:23 -080020 return QList<Token>();
21 });
swissChili5d3e5562022-02-24 16:49:19 -080022
23 _sleep.addNativeSentence("s.Time", [](VarContext args)
24 {
25 Token time = args.singleVar("Time");
26
27 if (time.type() != Token::INTEGER)
28 rtError("Invalid argument", "First argument to <Time> must be an integer, got " + pprint(time));
29
30 QEventLoop loop;
31 QTimer timer;
32 timer.connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
33 timer.start(time.integer());
34 loop.exec();
35
36 return QList<Token>();
37 });
swissChili323883d2022-02-20 16:35:23 -080038}
39
40void StdLib::load(Evaluator &eval)
41{
42 eval.addFunction(_print);
43 eval.addFunction(_prout);
swissChili5d3e5562022-02-24 16:49:19 -080044 eval.addFunction(_sleep);
swissChili323883d2022-02-20 16:35:23 -080045}