Example #1
0
QScriptEngine * PERPScriptEngine::newEngine(QObject *parent, QScriptEngineDebugger *debugger)
{
	QScriptEngine *engine = new QScriptEngine(parent);
	if ( debugger != NULL ) {
		debugger->attachTo(engine);
	}
	PERPScriptEngine::registerScriptsTypes(engine);
	engine->installTranslatorFunctions();
	PERPScriptEngine::importExtensions(engine);
	return engine;
}
Example #2
0
//! [0]
int main(int argc, char *argv[])
{
    Q_INIT_RESOURCE(helloscript);
//! [0]

//! [1]
    QApplication app(argc, argv);

    QScriptEngine engine;

    QTranslator translator;
    translator.load("helloscript_la");
    app.installTranslator(&translator);
    engine.installTranslatorFunctions();
//! [1]

//! [2]
    QPushButton button;
    QScriptValue scriptButton = engine.newQObject(&button);
    engine.globalObject().setProperty("button", scriptButton);
//! [2]

//! [3]
    QString fileName(":/helloscript.js");
    QFile scriptFile(fileName);
    scriptFile.open(QIODevice::ReadOnly);
    QTextStream stream(&scriptFile);
    QString contents = stream.readAll();
    scriptFile.close();
//! [3]

#ifdef Q_OS_SYMBIAN
    contents.replace("button.show()", "button.showMaximized()");
#endif

//! [4]
    QScriptValue result = engine.evaluate(contents, fileName);
//! [4]

//! [5]
    if (result.isError()) {
        QMessageBox::critical(0, "Hello Script",
                              QString::fromLatin1("%0:%1: %2")
                              .arg(fileName)
                              .arg(result.property("lineNumber").toInt32())
                              .arg(result.toString()));
        return -1;
    }
//! [5]

//! [6]
    return app.exec();
}
Example #3
0
File: qts.cpp Project: KDE/kross
int main(int argc, char **argv)
{
    QApplication *app = new QApplication(argc, argv);
    app->setApplicationName("kross");
    app->setApplicationVersion("0.1");
    app->setOrganizationDomain("dipe.org");

    QScriptEngine *engine = new QScriptEngine();
    engine->installTranslatorFunctions();

    /*K4AboutData about("kross",0,ki18n("Kross"),"0.1",
                     ki18n("KDE application to run Kross scripts."),
                     K4AboutData::License_LGPL,
                     ki18n("(C) 2006 Sebastian Sauer"),
                     ki18n("Run Kross scripts."),
                     "http://kross.dipe.org","[email protected]");*/
    //about.addAuthor(ki18n("Sebastian Sauer"), ki18n("Author"), "[email protected]");

    // Initialize command line args
    // Tell which options are supported and parse them.
    QCommandLineParser parser;
    parser.setApplicationDescription(QCoreApplication::translate("main", "KDE application to run Kross scripts."));
    parser.addHelpOption();
    parser.addOption(QCommandLineOption(QStringList() << "+file", QCoreApplication::translate("main", "Scriptfile")));
    parser.process(*app);

    const QStringList args = parser.positionalArguments();
    // If no options are defined.
    if (args.count() < 1) {
        parser.showHelp();
        //std::cout << "Syntax: " << "kross" << " scriptfile1 [scriptfile2] [scriptfile3] ..." << std::endl;
        return -1;
    }

    QScriptValue global = engine->globalObject();

    //qDebug()<<"QLibraryInfo::PluginsPath="<<QLibraryInfo::location(QLibraryInfo::PluginsPath);

    engine->importExtension("kross").toString();

    foreach (const QString &file, args) {
        runScriptFile(engine, file);
    }