From c6a2f4fa7d5930fe54d99a688b428f469dbe0e4c Mon Sep 17 00:00:00 2001 From: ErodeesFleurs <3353309908@qq.com> Date: Sat, 16 Mar 2024 20:00:53 +0800 Subject: [PATCH] add clipboard lua binds --- source/client/StarClientApplication.cpp | 3 +++ source/frontend/CMakeLists.txt | 2 ++ source/frontend/StarClipboardLuaBindings.cpp | 24 ++++++++++++++++++++ source/frontend/StarClipboardLuaBindings.hpp | 12 ++++++++++ 4 files changed, 41 insertions(+) create mode 100644 source/frontend/StarClipboardLuaBindings.cpp create mode 100644 source/frontend/StarClipboardLuaBindings.hpp diff --git a/source/client/StarClientApplication.cpp b/source/client/StarClientApplication.cpp index 3370802..e5cf601 100644 --- a/source/client/StarClientApplication.cpp +++ b/source/client/StarClientApplication.cpp @@ -21,6 +21,7 @@ #include "StarInterfaceLuaBindings.hpp" #include "StarInputLuaBindings.hpp" #include "StarVoiceLuaBindings.hpp" +#include "StarClipboardLuaBindings.hpp" #if defined STAR_SYSTEM_WINDOWS #include @@ -516,6 +517,8 @@ void ClientApplication::changeState(MainAppState newState) { m_universeClient->setLuaCallbacks("input", LuaBindings::makeInputCallbacks()); m_universeClient->setLuaCallbacks("voice", LuaBindings::makeVoiceCallbacks()); + if(!m_root->configuration()->get("safeScripts").toBool()) + m_universeClient->setLuaCallbacks("clipboard", LuaBindings::makeClipboardCallbacks(appController())); auto heldScriptPanes = make_shared>(); diff --git a/source/frontend/CMakeLists.txt b/source/frontend/CMakeLists.txt index cae2d43..0934308 100644 --- a/source/frontend/CMakeLists.txt +++ b/source/frontend/CMakeLists.txt @@ -23,6 +23,7 @@ SET (star_frontend_HEADERS StarChatBubbleManager.hpp StarCinematic.hpp StarClientCommandProcessor.hpp + StarClipboardLuaBindings.hpp StarCodexInterface.hpp StarConfirmationDialog.hpp StarContainerInterface.hpp @@ -74,6 +75,7 @@ SET (star_frontend_SOURCES StarChatBubbleManager.cpp StarCinematic.cpp StarClientCommandProcessor.cpp + StarClipboardLuaBindings.cpp StarCodexInterface.cpp StarConfirmationDialog.cpp StarContainerInterface.cpp diff --git a/source/frontend/StarClipboardLuaBindings.cpp b/source/frontend/StarClipboardLuaBindings.cpp new file mode 100644 index 0000000..c4fbc41 --- /dev/null +++ b/source/frontend/StarClipboardLuaBindings.cpp @@ -0,0 +1,24 @@ +#include "StarClipboardLuaBindings.hpp" +#include "StarLuaConverters.hpp" + +#include "SDL2/SDL.h" + +namespace Star { + +LuaCallbacks LuaBindings::makeClipboardCallbacks(ApplicationControllerPtr appController) { + LuaCallbacks callbacks; + + callbacks.registerCallback("hasText", []() -> bool { return SDL_HasClipboardText() == SDL_TRUE;}); + + callbacks.registerCallback("getText", [appController]() -> Maybe { + return appController->getClipboard(); + }); + + callbacks.registerCallback("setText", [appController](String const& text) { + appController->setClipboard(text); + }); + + return callbacks; +}; + +}// namespace Star diff --git a/source/frontend/StarClipboardLuaBindings.hpp b/source/frontend/StarClipboardLuaBindings.hpp new file mode 100644 index 0000000..7515c0b --- /dev/null +++ b/source/frontend/StarClipboardLuaBindings.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "StarLua.hpp" +#include "StarApplicationController.hpp" + +namespace Star { + +namespace LuaBindings { +LuaCallbacks makeClipboardCallbacks(ApplicationControllerPtr appController); +} + +}// namespace Star