Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 207 files). Show all
Unified · Split
| @@ -35,6 +35,7 @@ · 34 unmodified lines | ||
| 35 | 35 | #include "MenuItemProperties.h" |
| 36 | 36 | #include "LocalVoxels.h" |
| 37 | 37 | #include "ScriptEngine.h" |
| 38 | +#include "XMLHttpRequestClass.h" | |
| 38 | 39 | |
| 39 | 40 | VoxelsScriptingInterface ScriptEngine::_voxelsScriptingInterface; |
| 40 | 41 | ParticlesScriptingInterface ScriptEngine::_particlesScriptingInterface; |
| @@ -49,7 +50,12 @@ static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* eng · 8 unmodified lines | ||
| 49 | 50 | |
| 50 | 51 | static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ |
| 51 | 52 | qDebug() << "script:print()<<" << context->argument(0).toString(); |
| 52 | − engine->evaluate("Script.print('" + context->argument(0).toString() + "')"); | |
| 53 | + QString message = context->argument(0).toString() | |
| 54 | + .replace("\\", "\\\\") | |
| 55 | + .replace("\n", "\\n") | |
| 56 | + .replace("\r", "\\r") | |
| 57 | + .replace("'", "\\'"); | |
| 58 | + engine->evaluate("Script.print('" + message + "')"); | |
| 53 | 59 | return QScriptValue(); |
| 54 | 60 | } |
| 55 | 61 | |
| @@ -218,12 +224,16 @@ void ScriptEngine::init() { · 162 unmodified lines | ||
| 218 | 224 | |
| 219 | 225 | qScriptRegisterMetaType(&_engine, ModelItemPropertiesToScriptValue, ModelItemPropertiesFromScriptValue); |
| 220 | 226 | qScriptRegisterMetaType(&_engine, ModelItemIDtoScriptValue, ModelItemIDfromScriptValue); |
| 227 | + qScriptRegisterMetaType(&_engine, RayToModelIntersectionResultToScriptValue, RayToModelIntersectionResultFromScriptValue); | |
| 221 | 228 | qScriptRegisterSequenceMetaType<QVector<ModelItemID> >(&_engine); |
| 222 | 229 | |
| 223 | 230 | qScriptRegisterSequenceMetaType<QVector<glm::vec2> >(&_engine); |
| 224 | 231 | qScriptRegisterSequenceMetaType<QVector<glm::quat> >(&_engine); |
| 225 | 232 | qScriptRegisterSequenceMetaType<QVector<QString> >(&_engine); |
| 226 | 233 | |
| 234 | + QScriptValue xmlHttpRequestConstructorValue = _engine.newFunction(XMLHttpRequestClass::constructor); | |
| 235 | + _engine.globalObject().setProperty("XMLHttpRequest", xmlHttpRequestConstructorValue); | |
| 236 | + | |
| 227 | 237 | QScriptValue printConstructorValue = _engine.newFunction(debugPrint); |
| 228 | 238 | _engine.globalObject().setProperty("print", printConstructorValue); |
| 229 | 239 | |
| @@ -611,8 +621,20 @@ void ScriptEngine::include(const QString& includeFile) { · 381 unmodified lines | ||
| 611 | 621 | QUrl url = resolveInclude(includeFile); |
| 612 | 622 | QString includeContents; |
| 613 | 623 | |
| 614 | − if (url.scheme() == "file") { | |
| 624 | + if (url.scheme() == "http" || url.scheme() == "ftp") { | |
| 625 | + QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); | |
| 626 | + QNetworkReply* reply = networkManager->get(QNetworkRequest(url)); | |
| 627 | + qDebug() << "Downloading included script at" << includeFile; | |
| 628 | + QEventLoop loop; | |
| 629 | + QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); | |
| 630 | + loop.exec(); | |
| 631 | + includeContents = reply->readAll(); | |
| 632 | + } else { | |
| 633 | +#ifdef _WIN32 | |
| 634 | + QString fileName = url.toString(); | |
| 635 | +#else | |
| 615 | 636 | QString fileName = url.toLocalFile(); |
| 637 | +#endif | |
| 616 | 638 | QFile scriptFile(fileName); |
| 617 | 639 | if (scriptFile.open(QFile::ReadOnly | QFile::Text)) { |
| 618 | 640 | qDebug() << "Loading file:" << fileName; |
| @@ -622,14 +644,6 @@ void ScriptEngine::include(const QString& includeFile) { · 3 unmodified lines | ||
| 622 | 644 | qDebug() << "ERROR Loading file:" << fileName; |
| 623 | 645 | emit errorMessage("ERROR Loading file:" + fileName); |
| 624 | 646 | } |
| 625 | − } else { | |
| 626 | − QNetworkAccessManager* networkManager = new QNetworkAccessManager(this); | |
| 627 | − QNetworkReply* reply = networkManager->get(QNetworkRequest(url)); | |
| 628 | − qDebug() << "Downloading included script at" << includeFile; | |
| 629 | − QEventLoop loop; | |
| 630 | − QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); | |
| 631 | − loop.exec(); | |
| 632 | − includeContents = reply->readAll(); | |
| 633 | 647 | } |
| 634 | 648 | |
| 635 | 649 | QScriptValue result = _engine.evaluate(includeContents); |