mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 04:14:38 +02:00
Keep return script value
This commit is contained in:
parent
34ab0f10e0
commit
e2b140848f
2 changed files with 30 additions and 29 deletions
|
@ -297,10 +297,10 @@ ScriptManager::ScriptManager(Context context, const QString& scriptContents, con
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_areMetaTypesInitialized) {
|
if (!_areMetaTypesInitialized) {
|
||||||
initMetaTypes();
|
initMetaTypes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ScriptManager::getTypeAsString() const {
|
QString ScriptManager::getTypeAsString() const {
|
||||||
|
@ -826,9 +826,9 @@ void ScriptManager::run() {
|
||||||
// (because we're a client script)
|
// (because we're a client script)
|
||||||
hifi::scripting::setLocalAccessSafeThread(true);
|
hifi::scripting::setLocalAccessSafeThread(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
_engine->enterIsolateOnThisThread();
|
_engine->enterIsolateOnThisThread();
|
||||||
|
|
||||||
auto filenameParts = _fileNameString.split("/");
|
auto filenameParts = _fileNameString.split("/");
|
||||||
auto name = filenameParts.size() > 0 ? filenameParts[filenameParts.size() - 1] : "unknown";
|
auto name = filenameParts.size() > 0 ? filenameParts[filenameParts.size() - 1] : "unknown";
|
||||||
PROFILE_SET_THREAD_NAME("Script: " + name);
|
PROFILE_SET_THREAD_NAME("Script: " + name);
|
||||||
|
@ -848,7 +848,7 @@ void ScriptManager::run() {
|
||||||
|
|
||||||
{
|
{
|
||||||
PROFILE_RANGE(script, _fileNameString);
|
PROFILE_RANGE(script, _fileNameString);
|
||||||
_engine->evaluate(_scriptContents, _fileNameString);
|
_returnValue = _engine->evaluate(_scriptContents, _fileNameString);
|
||||||
_engine->maybeEmitUncaughtException(__FUNCTION__);
|
_engine->maybeEmitUncaughtException(__FUNCTION__);
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
|
@ -216,7 +216,7 @@ public:
|
||||||
* Script.setInterval(function () {
|
* Script.setInterval(function () {
|
||||||
* print("Hello");
|
* print("Hello");
|
||||||
* }, 1000);
|
* }, 1000);
|
||||||
*
|
*
|
||||||
* Script.setTimeout(function () {
|
* Script.setTimeout(function () {
|
||||||
* Script.stop(true);
|
* Script.stop(true);
|
||||||
* }, 5000);
|
* }, 5000);
|
||||||
|
@ -254,7 +254,7 @@ public:
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Checks whether the script is running as an Interface or avatar script.
|
* Checks whether the script is running as an Interface or avatar script.
|
||||||
* @function Script.isClientScript
|
* @function Script.isClientScript
|
||||||
* @returns {boolean} <code>true</code> if the script is running as an Interface or avatar script, <code>false</code> if it
|
* @returns {boolean} <code>true</code> if the script is running as an Interface or avatar script, <code>false</code> if it
|
||||||
* isn't.
|
* isn't.
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE bool isClientScript() const { return _context == CLIENT_SCRIPT; }
|
Q_INVOKABLE bool isClientScript() const { return _context == CLIENT_SCRIPT; }
|
||||||
|
@ -262,7 +262,7 @@ public:
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Checks whether the application was compiled as a debug build.
|
* Checks whether the application was compiled as a debug build.
|
||||||
* @function Script.isDebugMode
|
* @function Script.isDebugMode
|
||||||
* @returns {boolean} <code>true</code> if the application was compiled as a debug build, <code>false</code> if it was
|
* @returns {boolean} <code>true</code> if the application was compiled as a debug build, <code>false</code> if it was
|
||||||
* compiled as a release build.
|
* compiled as a release build.
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE bool isDebugMode() const;
|
Q_INVOKABLE bool isDebugMode() const;
|
||||||
|
@ -284,7 +284,7 @@ public:
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Checks whether the script is running as an assignment client script.
|
* Checks whether the script is running as an assignment client script.
|
||||||
* @function Script.isAgentScript
|
* @function Script.isAgentScript
|
||||||
* @returns {boolean} <code>true</code> if the script is running as an assignment client script, <code>false</code> if it
|
* @returns {boolean} <code>true</code> if the script is running as an assignment client script, <code>false</code> if it
|
||||||
* isn't.
|
* isn't.
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE bool isAgentScript() const { return _context == AGENT_SCRIPT; }
|
Q_INVOKABLE bool isAgentScript() const { return _context == AGENT_SCRIPT; }
|
||||||
|
@ -316,7 +316,7 @@ public:
|
||||||
* @function Script.addEventHandler
|
* @function Script.addEventHandler
|
||||||
* @param {Uuid} entityID - The ID of the entity.
|
* @param {Uuid} entityID - The ID of the entity.
|
||||||
* @param {Script.EntityEvent} eventName - The name of the event.
|
* @param {Script.EntityEvent} eventName - The name of the event.
|
||||||
* @param {Script~entityEventCallback|Script~pointerEventCallback|Script~collisionEventCallback} handler - The function to
|
* @param {Script~entityEventCallback|Script~pointerEventCallback|Script~collisionEventCallback} handler - The function to
|
||||||
* call when the event occurs on the entity. It can be either the name of a function or an in-line definition.
|
* call when the event occurs on the entity. It can be either the name of a function or an in-line definition.
|
||||||
* @example <caption>Report when a mouse press occurs on a particular entity.</caption>
|
* @example <caption>Report when a mouse press occurs on a particular entity.</caption>
|
||||||
* var entityID = Entities.addEntity({
|
* var entityID = Entities.addEntity({
|
||||||
|
@ -325,11 +325,11 @@ public:
|
||||||
* dimensions: { x: 0.5, y: 0.5, z: 0.5 },
|
* dimensions: { x: 0.5, y: 0.5, z: 0.5 },
|
||||||
* lifetime: 300 // Delete after 5 minutes.
|
* lifetime: 300 // Delete after 5 minutes.
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* function reportMousePress(entityID, event) {
|
* function reportMousePress(entityID, event) {
|
||||||
* print("Mouse pressed on entity: " + JSON.stringify(event));
|
* print("Mouse pressed on entity: " + JSON.stringify(event));
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* Script.addEventHandler(entityID, "mousePressOnEntity", reportMousePress);
|
* Script.addEventHandler(entityID, "mousePressOnEntity", reportMousePress);
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE void addEventHandler(const EntityItemID& entityID, const QString& eventName, const ScriptValue& handler);
|
Q_INVOKABLE void addEventHandler(const EntityItemID& entityID, const QString& eventName, const ScriptValue& handler);
|
||||||
|
@ -345,7 +345,7 @@ public:
|
||||||
Q_INVOKABLE void removeEventHandler(const EntityItemID& entityID, const QString& eventName, const ScriptValue& handler);
|
Q_INVOKABLE void removeEventHandler(const EntityItemID& entityID, const QString& eventName, const ScriptValue& handler);
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Starts running another script in Interface, if it isn't already running. The script is not automatically loaded next
|
* Starts running another script in Interface, if it isn't already running. The script is not automatically loaded next
|
||||||
* time Interface starts.
|
* time Interface starts.
|
||||||
* <p class="availableIn"><strong>Supported Script Types:</strong> Interface Scripts • Avatar Scripts</p>
|
* <p class="availableIn"><strong>Supported Script Types:</strong> Interface Scripts • Avatar Scripts</p>
|
||||||
* <p>See also, {@link ScriptDiscoveryService.loadScript}.</p>
|
* <p>See also, {@link ScriptDiscoveryService.loadScript}.</p>
|
||||||
|
@ -367,13 +367,13 @@ public:
|
||||||
Q_INVOKABLE void load(const QString& loadfile);
|
Q_INVOKABLE void load(const QString& loadfile);
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Includes JavaScript from other files in the current script. If a callback is specified, the files are loaded and
|
* Includes JavaScript from other files in the current script. If a callback is specified, the files are loaded and
|
||||||
* included asynchronously, otherwise they are included synchronously (i.e., script execution blocks while the files are
|
* included asynchronously, otherwise they are included synchronously (i.e., script execution blocks while the files are
|
||||||
* included).
|
* included).
|
||||||
* @function Script.include
|
* @function Script.include
|
||||||
* @variation 0
|
* @variation 0
|
||||||
* @param {string[]} filenames - The URLs of the scripts to include. Each can be relative to the current script.
|
* @param {string[]} filenames - The URLs of the scripts to include. Each can be relative to the current script.
|
||||||
* @param {function} [callback=null] - The function to call back when the scripts have been included. It can be either the
|
* @param {function} [callback=null] - The function to call back when the scripts have been included. It can be either the
|
||||||
* name of a function or an in-line definition.
|
* name of a function or an in-line definition.
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE void include(const QStringList& includeFiles, const ScriptValue& callback = ScriptValue());
|
Q_INVOKABLE void include(const QStringList& includeFiles, const ScriptValue& callback = ScriptValue());
|
||||||
|
@ -383,7 +383,7 @@ public:
|
||||||
* asynchronously, otherwise it is included synchronously (i.e., script execution blocks while the file is included).
|
* asynchronously, otherwise it is included synchronously (i.e., script execution blocks while the file is included).
|
||||||
* @function Script.include
|
* @function Script.include
|
||||||
* @param {string} filename - The URL of the script to include. It can be relative to the current script.
|
* @param {string} filename - The URL of the script to include. It can be relative to the current script.
|
||||||
* @param {function} [callback=null] - The function to call back when the script has been included. It can be either the
|
* @param {function} [callback=null] - The function to call back when the script has been included. It can be either the
|
||||||
* name of a function or an in-line definition.
|
* name of a function or an in-line definition.
|
||||||
* @example <caption>Include a script file asynchronously.</caption>
|
* @example <caption>Include a script file asynchronously.</caption>
|
||||||
* // First file: scriptA.js
|
* // First file: scriptA.js
|
||||||
|
@ -407,12 +407,12 @@ public:
|
||||||
// MODULE related methods
|
// MODULE related methods
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Provides access to methods or objects provided in an external JavaScript or JSON file.
|
* Provides access to methods or objects provided in an external JavaScript or JSON file.
|
||||||
* See {@link https://docs.overte.org/script/js-tips.html} for further details.
|
* See {@link https://docs.overte.org/script/js-tips.html} for further details.
|
||||||
* @function Script.require
|
* @function Script.require
|
||||||
* @param {string} module - The module to use. May be a JavaScript file, a JSON file, or the name of a system module such
|
* @param {string} module - The module to use. May be a JavaScript file, a JSON file, or the name of a system module such
|
||||||
* as <code>"appUi"</code> (i.e., the "appUi.js" system module JavaScript file).
|
* as <code>"appUi"</code> (i.e., the "appUi.js" system module JavaScript file).
|
||||||
* @returns {object|array} The value assigned to <code>module.exports</code> in the JavaScript file, or the value defined
|
* @returns {object|array} The value assigned to <code>module.exports</code> in the JavaScript file, or the value defined
|
||||||
* in the JSON file.
|
* in the JSON file.
|
||||||
*/
|
*/
|
||||||
Q_INVOKABLE ScriptValue require(const QString& moduleId);
|
Q_INVOKABLE ScriptValue require(const QString& moduleId);
|
||||||
|
@ -525,7 +525,7 @@ public:
|
||||||
Q_INVOKABLE QUrl resourcesPath() const;
|
Q_INVOKABLE QUrl resourcesPath() const;
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Starts timing a section of code in order to send usage data about it to Vircadia. Shouldn't be used outside of the
|
* Starts timing a section of code in order to send usage data about it to Vircadia. Shouldn't be used outside of the
|
||||||
* standard scripts.
|
* standard scripts.
|
||||||
* @function Script.beginProfileRange
|
* @function Script.beginProfileRange
|
||||||
* @param {string} label - A name that identifies the section of code.
|
* @param {string} label - A name that identifies the section of code.
|
||||||
|
@ -533,7 +533,7 @@ public:
|
||||||
Q_INVOKABLE void beginProfileRange(const QString& label) const;
|
Q_INVOKABLE void beginProfileRange(const QString& label) const;
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Finishes timing a section of code in order to send usage data about it to Vircadia. Shouldn't be used outside of
|
* Finishes timing a section of code in order to send usage data about it to Vircadia. Shouldn't be used outside of
|
||||||
* the standard scripts.
|
* the standard scripts.
|
||||||
* @function Script.endProfileRange
|
* @function Script.endProfileRange
|
||||||
* @param {string} label - A name that identifies the section of code.
|
* @param {string} label - A name that identifies the section of code.
|
||||||
|
@ -558,7 +558,7 @@ public:
|
||||||
QFuture<QVariant> getLocalEntityScriptDetails(const EntityItemID& entityID) override;
|
QFuture<QVariant> getLocalEntityScriptDetails(const EntityItemID& entityID) override;
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Manually runs the JavaScript garbage collector which reclaims memory by disposing of objects that are no longer
|
* Manually runs the JavaScript garbage collector which reclaims memory by disposing of objects that are no longer
|
||||||
* reachable.
|
* reachable.
|
||||||
* @function Script.requestGarbageCollection
|
* @function Script.requestGarbageCollection
|
||||||
*/
|
*/
|
||||||
|
@ -683,9 +683,9 @@ public:
|
||||||
* but this method will return the asset's current URL.)
|
* but this method will return the asset's current URL.)
|
||||||
* @function Script.getExternalPath
|
* @function Script.getExternalPath
|
||||||
* @param {Script.ResourceBucket} bucket - The external resource bucket that the asset is in.
|
* @param {Script.ResourceBucket} bucket - The external resource bucket that the asset is in.
|
||||||
* @param {string} path - The path within the external resource bucket where the asset is located.
|
* @param {string} path - The path within the external resource bucket where the asset is located.
|
||||||
* <p>Normally, this should start with a path or filename to be appended to the bucket URL.
|
* <p>Normally, this should start with a path or filename to be appended to the bucket URL.
|
||||||
* Alternatively, it can be a relative path starting with <code>./</code> or <code>../</code>, to navigate within the
|
* Alternatively, it can be a relative path starting with <code>./</code> or <code>../</code>, to navigate within the
|
||||||
* resource bucket's URL.</p>
|
* resource bucket's URL.</p>
|
||||||
* @Returns {string} The URL of an external asset.
|
* @Returns {string} The URL of an external asset.
|
||||||
* @example <caption>Report the URL of a default particle.</caption>
|
* @example <caption>Report the URL of a default particle.</caption>
|
||||||
|
@ -762,8 +762,8 @@ signals:
|
||||||
void finished(const QString& fileNameString, ScriptManagerPointer);
|
void finished(const QString& fileNameString, ScriptManagerPointer);
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Triggered when the script prints a message to the program log via {@link print}, {@link Script.print},
|
* Triggered when the script prints a message to the program log via {@link print}, {@link Script.print},
|
||||||
* {@link console.log}, {@link console.debug}, {@link console.group}, {@link console.groupEnd}, {@link console.time}, or
|
* {@link console.log}, {@link console.debug}, {@link console.group}, {@link console.groupEnd}, {@link console.time}, or
|
||||||
* {@link console.timeEnd}.
|
* {@link console.timeEnd}.
|
||||||
* @function Script.printedMessage
|
* @function Script.printedMessage
|
||||||
* @param {string} message - The message.
|
* @param {string} message - The message.
|
||||||
|
@ -773,7 +773,7 @@ signals:
|
||||||
void printedMessage(const QString& message, const QString& scriptName);
|
void printedMessage(const QString& message, const QString& scriptName);
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Triggered when the script generates an error, {@link console.error} or {@link console.exception} is called, or
|
* Triggered when the script generates an error, {@link console.error} or {@link console.exception} is called, or
|
||||||
* {@link console.assert} is called and fails.
|
* {@link console.assert} is called and fails.
|
||||||
* @function Script.errorMessage
|
* @function Script.errorMessage
|
||||||
* @param {string} message - The error message.
|
* @param {string} message - The error message.
|
||||||
|
@ -900,7 +900,7 @@ signals:
|
||||||
protected:
|
protected:
|
||||||
// Is called by the constructor, bceause all types need to be registered before method discovery with ScriptObjectV8Proxy::investigate()
|
// Is called by the constructor, bceause all types need to be registered before method discovery with ScriptObjectV8Proxy::investigate()
|
||||||
void initMetaTypes();
|
void initMetaTypes();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
|
@ -968,6 +968,7 @@ protected:
|
||||||
mutable QReadWriteLock _entityScriptsLock { QReadWriteLock::Recursive };
|
mutable QReadWriteLock _entityScriptsLock { QReadWriteLock::Recursive };
|
||||||
QHash<EntityItemID, EntityScriptDetails> _entityScripts;
|
QHash<EntityItemID, EntityScriptDetails> _entityScripts;
|
||||||
EntityScriptContentAvailableMap _contentAvailableQueue;
|
EntityScriptContentAvailableMap _contentAvailableQueue;
|
||||||
|
ScriptValue _returnValue;
|
||||||
|
|
||||||
bool _isThreaded { false };
|
bool _isThreaded { false };
|
||||||
qint64 _lastUpdate;
|
qint64 _lastUpdate;
|
||||||
|
|
Loading…
Reference in a new issue