File: main.cpp

package info (click to toggle)
actiona 3.11.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 54,580 kB
  • sloc: cpp: 969,398; xml: 52,881; javascript: 32,914; python: 23,909; sh: 550; ansic: 90; makefile: 9
file content (37 lines) | stat: -rw-r--r-- 889 bytes parent folder | download
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
#include <QFile>
#include <QTextStream>
#include <QApplication>

#include "RJSApi.h"

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    app.setQuitOnLastWindowClosed(true);

    if (argc < 2) {
        qDebug() << "Usage: " << argv[0] << " <JavaScript file>";
        return 1;
    }

    QString filePath = argv[1];
    QString fileContents;
    QFile file(filePath);
    if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QTextStream in(&file);
        fileContents = in.readAll();
        file.close();
    } else {
        qDebug() << "Failed to open the file: " << filePath;
        return 1;
    }

    QJSEngine* engine = new QJSEngine();
    RJSApi* rjsapi = new RJSApi(engine);
    rjsapi->init();

    QJSValue res = engine->evaluate(fileContents);
    qDebug() << "res:" << res.toString();

    //return app.exec();
    return res.toInt();
}