Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 15 files). Show all
Unified · Split
| @@ -43,6 +43,11 @@ static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* eng · 42 unmodified lines | |||
| 43 | return soundScriptValue; | 43 | return soundScriptValue; |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ | ||
| 47 | qDebug() << "script:print()<<" << context->argument(0).toString(); | ||
| 48 | engine->evaluate("Script.print('"+context->argument(0).toString()+"')"); | ||
| 49 | return QScriptValue(); | ||
| 50 | } | ||
| 46 | 51 | ||
| 47 | ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, | 52 | ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, |
| 48 | AbstractControllerScriptingInterface* controllerScriptingInterface) : | 53 | AbstractControllerScriptingInterface* controllerScriptingInterface) : |
| @@ -115,6 +120,7 @@ ScriptEngine::ScriptEngine(const QUrl& scriptURL, · 66 unmodified lines | |||
| 115 | _scriptContents = in.readAll(); | 120 | _scriptContents = in.readAll(); |
| 116 | } else { | 121 | } else { |
| 117 | qDebug() << "ERROR Loading file:" << fileName; | 122 | qDebug() << "ERROR Loading file:" << fileName; |
| 123 | emit errorMessage("ERROR Loading file:" + fileName); | ||
| 118 | } | 124 | } |
| 119 | } else { | 125 | } else { |
| 120 | QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); | 126 | QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); |
| @@ -200,6 +206,9 @@ void ScriptEngine::init() { · 79 unmodified lines | |||
| 200 | qScriptRegisterSequenceMetaType<QVector<glm::quat> >(&_engine); | 206 | qScriptRegisterSequenceMetaType<QVector<glm::quat> >(&_engine); |
| 201 | qScriptRegisterSequenceMetaType<QVector<QString> >(&_engine); | 207 | qScriptRegisterSequenceMetaType<QVector<QString> >(&_engine); |
| 202 | 208 | ||
| 209 | QScriptValue printConstructorValue = _engine.newFunction(debugPrint); | ||
| 210 | _engine.globalObject().setProperty("print", printConstructorValue); | ||
| 211 | |||
| 203 | QScriptValue soundConstructorValue = _engine.newFunction(soundConstructor); | 212 | QScriptValue soundConstructorValue = _engine.newFunction(soundConstructor); |
| 204 | QScriptValue soundMetaObject = _engine.newQMetaObject(&Sound::staticMetaObject, soundConstructorValue); | 213 | QScriptValue soundMetaObject = _engine.newQMetaObject(&Sound::staticMetaObject, soundConstructorValue); |
| 205 | _engine.globalObject().setProperty("Sound", soundMetaObject); | 214 | _engine.globalObject().setProperty("Sound", soundMetaObject); |
| @@ -246,6 +255,7 @@ void ScriptEngine::evaluate() { · 40 unmodified lines | |||
| 246 | if (_engine.hasUncaughtException()) { | 255 | if (_engine.hasUncaughtException()) { |
| 247 | int line = _engine.uncaughtExceptionLineNumber(); | 256 | int line = _engine.uncaughtExceptionLineNumber(); |
| 248 | qDebug() << "Uncaught exception at line" << line << ":" << result.toString(); | 257 | qDebug() << "Uncaught exception at line" << line << ":" << result.toString(); |
| 258 | emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + result.toString()); | ||
| 249 | } | 259 | } |
| 250 | } | 260 | } |
| 251 | 261 | ||
| @@ -266,11 +276,14 @@ void ScriptEngine::run() { · 14 unmodified lines | |||
| 266 | init(); | 276 | init(); |
| 267 | } | 277 | } |
| 268 | _isRunning = true; | 278 | _isRunning = true; |
| 279 | emit runningStateChanged(); | ||
| 269 | 280 | ||
| 270 | QScriptValue result = _engine.evaluate(_scriptContents); | 281 | QScriptValue result = _engine.evaluate(_scriptContents); |
| 271 | if (_engine.hasUncaughtException()) { | 282 | if (_engine.hasUncaughtException()) { |
| 272 | int line = _engine.uncaughtExceptionLineNumber(); | 283 | int line = _engine.uncaughtExceptionLineNumber(); |
| 284 | |||
| 273 | qDebug() << "Uncaught exception at line" << line << ":" << result.toString(); | 285 | qDebug() << "Uncaught exception at line" << line << ":" << result.toString(); |
| 286 | emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + result.toString()); | ||
| 274 | } | 287 | } |
| 275 | 288 | ||
| 276 | timeval startTime; | 289 | timeval startTime; |
| @@ -401,6 +414,7 @@ void ScriptEngine::run() { · 124 unmodified lines | |||
| 401 | if (_engine.hasUncaughtException()) { | 414 | if (_engine.hasUncaughtException()) { |
| 402 | int line = _engine.uncaughtExceptionLineNumber(); | 415 | int line = _engine.uncaughtExceptionLineNumber(); |
| 403 | qDebug() << "Uncaught exception at line" << line << ":" << _engine.uncaughtException().toString(); | 416 | qDebug() << "Uncaught exception at line" << line << ":" << _engine.uncaughtException().toString(); |
| 417 | emit errorMessage("Uncaught exception at line" + QString::number(line) + ":" + _engine.uncaughtException().toString()); | ||
| 404 | } | 418 | } |
| 405 | } | 419 | } |
| 406 | emit scriptEnding(); | 420 | emit scriptEnding(); |
| @@ -436,10 +450,12 @@ void ScriptEngine::run() { · 29 unmodified lines | |||
| 436 | emit finished(_fileNameString); | 450 | emit finished(_fileNameString); |
| 437 | 451 | ||
| 438 | _isRunning = false; | 452 | _isRunning = false; |
| 453 | emit runningStateChanged(); | ||
| 439 | } | 454 | } |
| 440 | 455 | ||
| 441 | void ScriptEngine::stop() { | 456 | void ScriptEngine::stop() { |
| 442 | _isFinished = true; | 457 | _isFinished = true; |
| 458 | emit runningStateChanged(); | ||
| 443 | } | 459 | } |
| 444 | 460 | ||
| 445 | void ScriptEngine::timerFired() { | 461 | void ScriptEngine::timerFired() { |
| @@ -510,6 +526,10 @@ QUrl ScriptEngine::resolveInclude(const QString& include) const { · 64 unmodified lines | |||
| 510 | return url; | 526 | return url; |
| 511 | } | 527 | } |
| 512 | 528 | ||
| 529 | void ScriptEngine::print(const QString& message) { | ||
| 530 | emit printedMessage(message); | ||
| 531 | } | ||
| 532 | |||
| 513 | void ScriptEngine::include(const QString& includeFile) { | 533 | void ScriptEngine::include(const QString& includeFile) { |
| 514 | QUrl url = resolveInclude(includeFile); | 534 | QUrl url = resolveInclude(includeFile); |
| 515 | QString includeContents; | 535 | QString includeContents; |
| @@ -523,6 +543,7 @@ void ScriptEngine::include(const QString& includeFile) { · 7 unmodified lines | |||
| 523 | includeContents = in.readAll(); | 543 | includeContents = in.readAll(); |
| 524 | } else { | 544 | } else { |
| 525 | qDebug() << "ERROR Loading file:" << fileName; | 545 | qDebug() << "ERROR Loading file:" << fileName; |
| 546 | emit errorMessage("ERROR Loading file:" + fileName); | ||
| 526 | } | 547 | } |
| 527 | } else { | 548 | } else { |
| 528 | QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); | 549 | QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); |
| @@ -538,5 +559,6 @@ void ScriptEngine::include(const QString& includeFile) { · 9 unmodified lines | |||
| 538 | if (_engine.hasUncaughtException()) { | 559 | if (_engine.hasUncaughtException()) { |
| 539 | int line = _engine.uncaughtExceptionLineNumber(); | 560 | int line = _engine.uncaughtExceptionLineNumber(); |
| 540 | qDebug() << "Uncaught exception at (" << includeFile << ") line" << line << ":" << result.toString(); | 561 | qDebug() << "Uncaught exception at (" << includeFile << ") line" << line << ":" << result.toString(); |
| 562 | emit errorMessage("Uncaught exception at (" + includeFile + ") line" + QString::number(line) + ":" + result.toString()); | ||
| 541 | } | 563 | } |
| 542 | } | 564 | } |