Skip to content

Commit 9f758c1

Browse files
authored
Merge pull request #38 from InputActions/scripting-globalThis
scripting: add globalThis
2 parents cc1175c + b1f2d3f commit 9f758c1

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/libinputactions/scripting/ScriptingEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void ScriptingEngine::initialize()
6767
}
6868
)");
6969

70-
m_coreModule = std::make_unique<CoreModule>();
70+
m_coreModule = std::make_unique<CoreModule>(m_engine->globalObject());
7171
QJSEngine::setObjectOwnership(m_coreModule.get(), QJSEngine::CppOwnership);
7272
auto coreModule = m_engine->newQObject(m_coreModule.get());
7373
coreModule.setProperty("Point", m_engine->newQMetaObject(&PointF::staticMetaObject));

src/libinputactions/scripting/modules/core/CoreModule.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
namespace InputActions
2626
{
2727

28-
CoreModule::CoreModule()
28+
CoreModule::CoreModule(QJSValue globalObject)
2929
: m_config(std::make_unique<Config>())
30+
, m_globalObject(std::move(globalObject))
3031
{
3132
QJSEngine::setObjectOwnership(m_config.get(), QJSEngine::CppOwnership);
3233
}

src/libinputactions/scripting/modules/core/CoreModule.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#pragma once
2020

21+
#include <QJSValue>
2122
#include <QObject>
2223

2324
namespace InputActions
@@ -32,19 +33,22 @@ class CoreModule : public QObject
3233
Q_OBJECT
3334

3435
Q_PROPERTY(Config *config READ config)
36+
Q_PROPERTY(QJSValue globalThis READ globalThis)
3537
Q_PROPERTY(InputBackend *input READ input)
3638
Q_PROPERTY(VariableRegistry *variableRegistry READ variableRegistry)
3739

3840
public:
39-
CoreModule();
41+
CoreModule(QJSValue globalObject);
4042
~CoreModule() override;
4143

4244
Config *config() const;
45+
QJSValue globalThis() const { return m_globalObject; }
4346
InputBackend *input() const;
4447
VariableRegistry *variableRegistry() const;
4548

4649
private:
4750
std::unique_ptr<Config> m_config;
51+
QJSValue m_globalObject;
4852
};
4953

5054
}

0 commit comments

Comments
 (0)