mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 02:43:32 +02:00
Some more script checks
This commit is contained in:
parent
13b7fa6b5d
commit
3e43a3c345
1 changed files with 9 additions and 17 deletions
|
@ -79,7 +79,6 @@ void avatarDataFromScriptValue(const QScriptValue &object, AvatarData* &out) {
|
||||||
QScriptValue inputControllerToScriptValue(QScriptEngine *engine, AbstractInputController* const &in) {
|
QScriptValue inputControllerToScriptValue(QScriptEngine *engine, AbstractInputController* const &in) {
|
||||||
return engine->newQObject(in);
|
return engine->newQObject(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inputControllerFromScriptValue(const QScriptValue &object, AbstractInputController* &out) {
|
void inputControllerFromScriptValue(const QScriptValue &object, AbstractInputController* &out) {
|
||||||
out = qobject_cast<AbstractInputController*>(object.toQObject());
|
out = qobject_cast<AbstractInputController*>(object.toQObject());
|
||||||
}
|
}
|
||||||
|
@ -95,9 +94,6 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam
|
||||||
_wantSignals(wantSignals),
|
_wantSignals(wantSignals),
|
||||||
_controllerScriptingInterface(controllerScriptingInterface),
|
_controllerScriptingInterface(controllerScriptingInterface),
|
||||||
_fileNameString(fileNameString),
|
_fileNameString(fileNameString),
|
||||||
_quatLibrary(),
|
|
||||||
_vec3Library(),
|
|
||||||
_uuidLibrary(),
|
|
||||||
_isUserLoaded(false),
|
_isUserLoaded(false),
|
||||||
_isReloading(false),
|
_isReloading(false),
|
||||||
_arrayBufferClass(new ArrayBufferClass(this))
|
_arrayBufferClass(new ArrayBufferClass(this))
|
||||||
|
@ -654,7 +650,9 @@ void ScriptEngine::run() {
|
||||||
}
|
}
|
||||||
lastUpdate = now;
|
lastUpdate = now;
|
||||||
|
|
||||||
checkExceptions(this, _fileNameString);
|
if (!checkExceptions(this, _fileNameString)) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stopAllTimers(); // make sure all our timers are stopped if the script is ending
|
stopAllTimers(); // make sure all our timers are stopped if the script is ending
|
||||||
|
@ -891,7 +889,6 @@ void ScriptEngine::load(const QString& loadFile) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ScriptEngine::checkSyntax(const QScriptProgram& program) {
|
bool ScriptEngine::checkSyntax(const QScriptProgram& program) {
|
||||||
const auto syntaxCheck = QScriptEngine::checkSyntax(program.sourceCode());
|
const auto syntaxCheck = QScriptEngine::checkSyntax(program.sourceCode());
|
||||||
if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
|
if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
|
||||||
|
@ -1005,14 +1002,10 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co
|
||||||
|
|
||||||
auto scriptCache = DependencyManager::get<ScriptCache>();
|
auto scriptCache = DependencyManager::get<ScriptCache>();
|
||||||
bool isFileUrl = isURL && scriptOrURL.startsWith("file://");
|
bool isFileUrl = isURL && scriptOrURL.startsWith("file://");
|
||||||
|
auto fileName = QString("(EntityID:%1, %2)").arg(entityID.toString(), isURL ? scriptOrURL : "EmbededEntityScript");
|
||||||
|
|
||||||
// first check the syntax of the script contents
|
QScriptProgram program(contents, fileName);
|
||||||
QScriptSyntaxCheckResult syntaxCheck = QScriptEngine::checkSyntax(contents);
|
if (!checkSyntax(program)) {
|
||||||
if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
|
|
||||||
qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID;
|
|
||||||
qCDebug(scriptengine) << " " << syntaxCheck.errorMessage() << ":"
|
|
||||||
<< syntaxCheck.errorLineNumber() << syntaxCheck.errorColumnNumber();
|
|
||||||
qCDebug(scriptengine) << " SCRIPT:" << scriptOrURL;
|
|
||||||
if (!isFileUrl) {
|
if (!isFileUrl) {
|
||||||
scriptCache->addScriptToBadScriptList(scriptOrURL);
|
scriptCache->addScriptToBadScriptList(scriptOrURL);
|
||||||
}
|
}
|
||||||
|
@ -1027,9 +1020,9 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co
|
||||||
QScriptValue testConstructor = sandbox.evaluate(contents);
|
QScriptValue testConstructor = sandbox.evaluate(contents);
|
||||||
|
|
||||||
if (!testConstructor.isFunction()) {
|
if (!testConstructor.isFunction()) {
|
||||||
qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID;
|
qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID << "\n"
|
||||||
qCDebug(scriptengine) << " NOT CONSTRUCTOR";
|
" NOT CONSTRUCTOR\n"
|
||||||
qCDebug(scriptengine) << " SCRIPT:" << scriptOrURL;
|
" SCRIPT:" << scriptOrURL;
|
||||||
if (!isFileUrl) {
|
if (!isFileUrl) {
|
||||||
scriptCache->addScriptToBadScriptList(scriptOrURL);
|
scriptCache->addScriptToBadScriptList(scriptOrURL);
|
||||||
}
|
}
|
||||||
|
@ -1042,7 +1035,6 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co
|
||||||
lastModified = (quint64)QFileInfo(file).lastModified().toMSecsSinceEpoch();
|
lastModified = (quint64)QFileInfo(file).lastModified().toMSecsSinceEpoch();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto fileName = QString("(EntityID:%1, %2)").arg(entityID.toString(), isURL ? scriptOrURL : "EmbededEntityScript");
|
|
||||||
QScriptValue entityScriptConstructor = evaluate(contents, fileName);
|
QScriptValue entityScriptConstructor = evaluate(contents, fileName);
|
||||||
QScriptValue entityScriptObject = entityScriptConstructor.construct();
|
QScriptValue entityScriptObject = entityScriptConstructor.construct();
|
||||||
EntityScriptDetails newDetails = { scriptOrURL, entityScriptObject, lastModified };
|
EntityScriptDetails newDetails = { scriptOrURL, entityScriptObject, lastModified };
|
||||||
|
|
Loading…
Reference in a new issue