From f3d49527b70d35be464c630c0b5c1c8981e12385 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 5 Feb 2023 21:20:27 -0800 Subject: [PATCH] Qt: Add scripting storage integration --- src/platform/qt/scripting/ScriptingController.cpp | 11 +++++++++++ src/platform/qt/scripting/ScriptingController.h | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/src/platform/qt/scripting/ScriptingController.cpp b/src/platform/qt/scripting/ScriptingController.cpp index b0fbd51ef..836e379f1 100644 --- a/src/platform/qt/scripting/ScriptingController.cpp +++ b/src/platform/qt/scripting/ScriptingController.cpp @@ -20,6 +20,7 @@ #include "scripting/ScriptingTextBufferModel.h" #include +#include #include #include @@ -51,6 +52,9 @@ ScriptingController::ScriptingController(QObject* parent) m_bufferModel = new ScriptingTextBufferModel(this); QObject::connect(m_bufferModel, &ScriptingTextBufferModel::textBufferCreated, this, &ScriptingController::textBufferCreated); + connect(&m_storageFlush, &QTimer::timeout, this, &ScriptingController::flushStorage); + m_storageFlush.setInterval(5); + mScriptGamepadInit(&m_gamepad); init(); @@ -144,6 +148,10 @@ void ScriptingController::runCode(const QString& code) { load(vf, "*prompt"); } +void ScriptingController::flushStorage() { + mScriptStorageFlushAll(&m_scriptContext); +} + bool ScriptingController::eventFilter(QObject* obj, QEvent* ev) { event(obj, ev); return false; @@ -293,6 +301,7 @@ void ScriptingController::detachGamepad() { void ScriptingController::init() { mScriptContextInit(&m_scriptContext); mScriptContextAttachStdlib(&m_scriptContext); + mScriptContextAttachStorage(&m_scriptContext); mScriptContextAttachSocket(&m_scriptContext); mScriptContextAttachInput(&m_scriptContext); mScriptContextRegisterEngines(&m_scriptContext); @@ -308,6 +317,8 @@ void ScriptingController::init() { if (m_engines.count() == 1) { m_activeEngine = *m_engines.begin(); } + + m_storageFlush.start(); } uint32_t ScriptingController::qtToScriptingKey(const QKeyEvent* event) { diff --git a/src/platform/qt/scripting/ScriptingController.h b/src/platform/qt/scripting/ScriptingController.h index 0e275561d..e34b34542 100644 --- a/src/platform/qt/scripting/ScriptingController.h +++ b/src/platform/qt/scripting/ScriptingController.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -55,6 +56,8 @@ public slots: void reset(); void runCode(const QString& code); + void flushStorage(); + protected: bool eventFilter(QObject*, QEvent*) override; @@ -84,6 +87,8 @@ private: std::shared_ptr m_controller; InputController* m_inputController = nullptr; + + QTimer m_storageFlush; }; }