Overte C++ Documentation
GraphicsScriptingUtil.h
1 //
2 // Copyright 2018-2019 High Fidelity, Inc.
3 // Copyright 2023 Overte e.V.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 // SPDX-License-Identifier: Apache-2.0
8 //
9 
10 #pragma once
11 
12 #include <QtCore/QPointer>
13 #include <QtCore/QObject>
14 #include <QtCore/QLoggingCategory>
15 #include <QDebug>
16 #include <memory>
17 #include <functional>
18 #include <glm/glm.hpp>
19 #include <ScriptValue.h>
20 
21 class ScriptEngine;
22 
23 class Extents;
24 class AABox;
25 namespace gpu {
26  class Element;
27 }
28 Q_DECLARE_LOGGING_CATEGORY(graphics_scripting)
29 
30 namespace scriptable {
31  QVariant toVariant(const Extents& box);
32  QVariant toVariant(const AABox& box);
33  QVariant toVariant(const gpu::Element& element);
34  QVariant toVariant(const glm::mat4& mat4);
35 
36  // helper that automatically resolves Qt-signal-like scoped callbacks
37  // ... C++ side: `void MyClass::asyncMethod(..., const ScriptValue& callback)`
38  // ... JS side:
39  // * `API.asyncMethod(..., function(){})`
40  // * `API.asyncMethod(..., scope, function(){})`
41  // * `API.asyncMethod(..., scope, "methodName")`
42  ScriptValue jsBindCallback(const ScriptValue& callback);
43 
44  // cast engine->thisObject() => C++ class instance
45  template <typename T> T this_qobject_cast(ScriptEngine* engine);
46 
47  QString toDebugString(QObject* tmp);
48  template <typename T> QString toDebugString(std::shared_ptr<T> tmp);
49 
50  // Helper for creating C++ > ScriptOwned JS instances
51  // (NOTE: this also helps track in the code where we need to update later if switching to
52  // std::shared_ptr's -- something currently non-trivial given mixed JS/C++ object ownership)
53  template <typename T, class... Rest> inline QPointer<T> make_scriptowned(Rest... rest) {
54  auto instance = QPointer<T>(new T(rest...));
55  Q_ASSERT(instance && instance->parent());
56  return instance;
57  }
58 }
Provides an engine-independent interface for a scripting engine.
Definition: ScriptEngine.h:93
[ScriptInterface] Provides an engine-independent interface for QScriptValue
Definition: ScriptValue.h:40