From 5b886fc51e03fbdba35d61eb22cfaf9b12403539 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Wed, 29 Jan 2014 17:57:10 -0500 Subject: [PATCH] boxmein: Added clipboard support to Lua --- src/lua/LegacyLuaAPI.cpp | 15 +++++++++++++++ src/lua/LuaScriptHelper.h | 3 +++ src/lua/LuaScriptInterface.cpp | 2 ++ 3 files changed, 20 insertions(+) diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index 4ce278a01..b56079bf8 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -9,6 +9,7 @@ #include "Format.h" #include "LuaScriptInterface.h" #include "LuaScriptHelper.h" +#include "PowderToy.h" #include "gui/dialogues/ErrorMessage.h" #include "gui/dialogues/InformationMessage.h" @@ -2053,4 +2054,18 @@ int luatpt_screenshot(lua_State* l) lua_pushstring(l, filename.str().c_str()); return 1; } + +int luatpt_getclip (lua_State* l) +{ + lua_pushstring(l, ClipboardPull()); + return 1; +} + +int luatpt_setclip (lua_State* l) +{ + luaL_checktype(l, 1, LUA_TSTRING); + ClipboardPush((char*) std::string(luaL_optstring(l, 1, "")).c_str()); + return 0; +} + #endif diff --git a/src/lua/LuaScriptHelper.h b/src/lua/LuaScriptHelper.h index 0c4af2895..40caa18a1 100644 --- a/src/lua/LuaScriptHelper.h +++ b/src/lua/LuaScriptHelper.h @@ -129,5 +129,8 @@ int luatpt_getscript(lua_State* l); int luatpt_setwindowsize(lua_State* l); int luatpt_screenshot(lua_State* l); +int luatpt_getclip(lua_State* l); +int luatpt_setclip(lua_State* l); + #endif /* LUASCRIPTHELPER_H_ */ diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 348b8351c..5ca7ba1a9 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -188,6 +188,8 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m): {"element",&luatpt_getelement}, {"element_func",&luatpt_element_func}, {"graphics_func",&luatpt_graphics_func}, + {"get_clipboard", &luatpt_getclip}, + {"set_clipboard", &luatpt_setclip}, {NULL,NULL} };