mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-08-03 23:36:59 -04:00
Merge branch 'clipped_and_shipped' into 'master'
Lua: Add basic clipboard bindings See merge request OpenMW/openmw!4824
This commit is contained in:
commit
ab106b250e
@ -63,7 +63,7 @@ add_openmw_dir (mwlua
|
|||||||
context menuscripts globalscripts localscripts playerscripts luabindings objectbindings cellbindings coremwscriptbindings
|
context menuscripts globalscripts localscripts playerscripts luabindings objectbindings cellbindings coremwscriptbindings
|
||||||
mwscriptbindings camerabindings vfsbindings uibindings soundbindings inputbindings nearbybindings dialoguebindings
|
mwscriptbindings camerabindings vfsbindings uibindings soundbindings inputbindings nearbybindings dialoguebindings
|
||||||
postprocessingbindings stats recordstore debugbindings corebindings worldbindings worker landbindings magicbindings factionbindings
|
postprocessingbindings stats recordstore debugbindings corebindings worldbindings worker landbindings magicbindings factionbindings
|
||||||
classbindings itemdata inputprocessor animationbindings birthsignbindings racebindings markupbindings weatherbindings
|
classbindings itemdata inputprocessor animationbindings birthsignbindings racebindings markupbindings weatherbindings clipboardbindings
|
||||||
types/types types/door types/item types/actor types/container types/lockable types/weapon types/npc
|
types/types types/door types/item types/actor types/container types/lockable types/weapon types/npc
|
||||||
types/creature types/player types/activator types/book types/lockpick types/probe types/apparatus
|
types/creature types/player types/activator types/book types/lockpick types/probe types/apparatus
|
||||||
types/potion types/ingredient types/misc types/repair types/armor types/light types/static
|
types/potion types/ingredient types/misc types/repair types/armor types/light types/static
|
||||||
|
41
apps/openmw/mwlua/clipboardbindings.cpp
Normal file
41
apps/openmw/mwlua/clipboardbindings.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include "clipboardbindings.hpp"
|
||||||
|
|
||||||
|
#include <SDL_clipboard.h>
|
||||||
|
#include <SDL_error.h>
|
||||||
|
|
||||||
|
#include <components/debug/debuglog.hpp>
|
||||||
|
|
||||||
|
#include "context.hpp"
|
||||||
|
|
||||||
|
namespace MWLua
|
||||||
|
{
|
||||||
|
sol::table initClipboardPackage(const Context& context)
|
||||||
|
{
|
||||||
|
sol::state_view lua = context.sol();
|
||||||
|
sol::table api(lua, sol::create);
|
||||||
|
|
||||||
|
api["get"] = []() {
|
||||||
|
std::string text;
|
||||||
|
|
||||||
|
char* raw = SDL_GetClipboardText();
|
||||||
|
text = raw;
|
||||||
|
|
||||||
|
SDL_free(raw);
|
||||||
|
|
||||||
|
return text;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto set = [](const char* data) {
|
||||||
|
if (SDL_SetClipboardText(data) != 0)
|
||||||
|
{
|
||||||
|
Log(Debug::Error) << "Failed to set clipboard content: " << SDL_GetError();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
api["set"] = [set](const std::string_view text) { set(text.data()); };
|
||||||
|
|
||||||
|
api["clear"] = [set]() { set(nullptr); };
|
||||||
|
|
||||||
|
return LuaUtil::makeReadOnly(api);
|
||||||
|
}
|
||||||
|
}
|
13
apps/openmw/mwlua/clipboardbindings.hpp
Normal file
13
apps/openmw/mwlua/clipboardbindings.hpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef MWLUA_CLIPBOARD_H
|
||||||
|
#define MWLUA_CLIPBOARD_H
|
||||||
|
|
||||||
|
#include <sol/forward.hpp>
|
||||||
|
|
||||||
|
namespace MWLua
|
||||||
|
{
|
||||||
|
struct Context;
|
||||||
|
|
||||||
|
sol::table initClipboardPackage(const Context&);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // MWLUA_CLIPBOARD_H
|
@ -10,6 +10,7 @@
|
|||||||
#include "animationbindings.hpp"
|
#include "animationbindings.hpp"
|
||||||
#include "camerabindings.hpp"
|
#include "camerabindings.hpp"
|
||||||
#include "cellbindings.hpp"
|
#include "cellbindings.hpp"
|
||||||
|
#include "clipboardbindings.hpp"
|
||||||
#include "corebindings.hpp"
|
#include "corebindings.hpp"
|
||||||
#include "debugbindings.hpp"
|
#include "debugbindings.hpp"
|
||||||
#include "inputbindings.hpp"
|
#include "inputbindings.hpp"
|
||||||
@ -62,6 +63,7 @@ namespace MWLua
|
|||||||
{ "openmw.core", initCorePackage(context) },
|
{ "openmw.core", initCorePackage(context) },
|
||||||
{ "openmw.types", initTypesPackage(context) },
|
{ "openmw.types", initTypesPackage(context) },
|
||||||
{ "openmw.nearby", initNearbyPackage(context) },
|
{ "openmw.nearby", initNearbyPackage(context) },
|
||||||
|
{ "openmw.clipboard", initClipboardPackage(context) },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +87,7 @@ namespace MWLua
|
|||||||
{ "openmw.ui", initUserInterfacePackage(context) },
|
{ "openmw.ui", initUserInterfacePackage(context) },
|
||||||
{ "openmw.menu", initMenuPackage(context) },
|
{ "openmw.menu", initMenuPackage(context) },
|
||||||
{ "openmw.input", initInputPackage(context) },
|
{ "openmw.input", initInputPackage(context) },
|
||||||
|
{ "openmw.clipboard", initClipboardPackage(context) },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ Packages
|
|||||||
async <openmw_async>
|
async <openmw_async>
|
||||||
camera <openmw_camera>
|
camera <openmw_camera>
|
||||||
core <openmw_core>
|
core <openmw_core>
|
||||||
|
clipboard <openmw_clipboard>
|
||||||
debug <openmw_debug>
|
debug <openmw_debug>
|
||||||
input <openmw_input>
|
input <openmw_input>
|
||||||
markup <openmw_markup>
|
markup <openmw_markup>
|
||||||
|
7
docs/source/reference/lua-scripting/openmw_clipboard.rst
Normal file
7
docs/source/reference/lua-scripting/openmw_clipboard.rst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Package openmw.clipboard
|
||||||
|
========================
|
||||||
|
|
||||||
|
.. include:: version.rst
|
||||||
|
|
||||||
|
.. raw:: html
|
||||||
|
:file: generated_html/openmw_clipboard.html
|
@ -20,6 +20,9 @@
|
|||||||
* - :doc:`core </reference/lua-scripting/openmw_core>`
|
* - :doc:`core </reference/lua-scripting/openmw_core>`
|
||||||
- |bdg-ctx-all|
|
- |bdg-ctx-all|
|
||||||
- Functions that are common for both global and local scripts
|
- Functions that are common for both global and local scripts
|
||||||
|
* - :doc:`clipboard </reference/lua-scripting/openmw_clipboard>`
|
||||||
|
- |bdg-ctx-local| |bdg-ctx-menu|
|
||||||
|
- Read and write access to the systems clipboard
|
||||||
* - :doc:`debug </reference/lua-scripting/openmw_debug>`
|
* - :doc:`debug </reference/lua-scripting/openmw_debug>`
|
||||||
- |bdg-ctx-player|
|
- |bdg-ctx-player|
|
||||||
- Collection of debug utils.
|
- Collection of debug utils.
|
||||||
|
@ -23,6 +23,7 @@ local env = {
|
|||||||
util = require('openmw.util'),
|
util = require('openmw.util'),
|
||||||
storage = require('openmw.storage'),
|
storage = require('openmw.storage'),
|
||||||
core = require('openmw.core'),
|
core = require('openmw.core'),
|
||||||
|
clipboard = require('openmw.clipboard'),
|
||||||
types = require('openmw.types'),
|
types = require('openmw.types'),
|
||||||
vfs = require('openmw.vfs'),
|
vfs = require('openmw.vfs'),
|
||||||
markup = require('openmw.markup'),
|
markup = require('openmw.markup'),
|
||||||
|
@ -45,6 +45,7 @@ local env = {
|
|||||||
menu = require('openmw.menu'),
|
menu = require('openmw.menu'),
|
||||||
util = require('openmw.util'),
|
util = require('openmw.util'),
|
||||||
core = require('openmw.core'),
|
core = require('openmw.core'),
|
||||||
|
clipboard = require('openmw.clipboard'),
|
||||||
storage = require('openmw.storage'),
|
storage = require('openmw.storage'),
|
||||||
vfs = require('openmw.vfs'),
|
vfs = require('openmw.vfs'),
|
||||||
markup = require('openmw.markup'),
|
markup = require('openmw.markup'),
|
||||||
|
@ -70,6 +70,7 @@ local env = {
|
|||||||
util = require('openmw.util'),
|
util = require('openmw.util'),
|
||||||
storage = require('openmw.storage'),
|
storage = require('openmw.storage'),
|
||||||
core = require('openmw.core'),
|
core = require('openmw.core'),
|
||||||
|
clipboard = require('openmw.clipboard'),
|
||||||
types = require('openmw.types'),
|
types = require('openmw.types'),
|
||||||
vfs = require('openmw.vfs'),
|
vfs = require('openmw.vfs'),
|
||||||
markup = require('openmw.markup'),
|
markup = require('openmw.markup'),
|
||||||
|
20
files/lua_api/openmw/clipboard.lua
Normal file
20
files/lua_api/openmw/clipboard.lua
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
-- Provides an interface to the systems clipboard.
|
||||||
|
-- @context local|menu
|
||||||
|
-- @module clipboard
|
||||||
|
-- @usage local clipboard = require('openmw.clipboard')
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Sets the clipboard from a UTF-8 encoded string
|
||||||
|
-- @function [parent=#clipboard] set()
|
||||||
|
-- @param #string text The text to set for the clipboard.
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Gets the clipboard content as a UTF-8 encoded string
|
||||||
|
-- @function [parent=#clipboard] get()
|
||||||
|
|
||||||
|
---
|
||||||
|
-- Clears the systems clipboard
|
||||||
|
-- @function [parent=#clipboard] clear()
|
||||||
|
|
||||||
|
return nil
|
Loading…
x
Reference in New Issue
Block a user