osb/source/frontend/StarClipboardLuaBindings.cpp

39 lines
947 B
C++
Raw Normal View History

2024-03-16 20:00:53 +08:00
#include "StarClipboardLuaBindings.hpp"
#include "StarLuaConverters.hpp"
#include "StarInput.hpp"
2024-03-16 20:00:53 +08:00
namespace Star {
LuaCallbacks LuaBindings::makeClipboardCallbacks(ApplicationControllerPtr appController, bool alwaysAllow) {
2024-03-16 20:00:53 +08:00
LuaCallbacks callbacks;
auto available = [alwaysAllow]() { return alwaysAllow || Input::singleton().getTag("clipboard") > 0; };
callbacks.registerCallback("available", [=]() -> bool {
return available();
});
callbacks.registerCallback("hasText", [=]() -> bool {
return available() && appController->hasClipboard();
});
2024-03-16 20:00:53 +08:00
callbacks.registerCallback("getText", [=]() -> Maybe<String> {
if (!available())
return {};
else
return appController->getClipboard();
2024-03-16 20:00:53 +08:00
});
callbacks.registerCallback("setText", [=](String const& text) -> bool {
if (available()) {
appController->setClipboard(text);
return true;
}
return false;
2024-03-16 20:00:53 +08:00
});
return callbacks;
};
}