add clipboard lua binds

This commit is contained in:
ErodeesFleurs 2024-03-16 20:00:53 +08:00
parent 5499b04e9f
commit c6a2f4fa7d
4 changed files with 41 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#include "StarInterfaceLuaBindings.hpp"
#include "StarInputLuaBindings.hpp"
#include "StarVoiceLuaBindings.hpp"
#include "StarClipboardLuaBindings.hpp"
#if defined STAR_SYSTEM_WINDOWS
#include <windows.h>
@ -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<List<MainInterface::ScriptPaneInfo>>();

View File

@ -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

View File

@ -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<String> {
return appController->getClipboard();
});
callbacks.registerCallback("setText", [appController](String const& text) {
appController->setClipboard(text);
});
return callbacks;
};
}// namespace Star

View File

@ -0,0 +1,12 @@
#pragma once
#include "StarLua.hpp"
#include "StarApplicationController.hpp"
namespace Star {
namespace LuaBindings {
LuaCallbacks makeClipboardCallbacks(ApplicationControllerPtr appController);
}
}// namespace Star