Clipboard API (Clipboard.write(string))
This commit is contained in:
@@ -871,6 +871,46 @@ var HTML_CONTENT_DOM_MANIPULATION = """
|
||||
""".to_utf8_buffer()
|
||||
|
||||
var HTML_CONTENT = """<head>
|
||||
<title>Network & Clipboard API Demo</title>
|
||||
<icon src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Lua-Logo.svg/256px-Lua-Logo.svg.png">
|
||||
<meta name="theme-color" content="#059669">
|
||||
<meta name="description" content="Demonstrating Network fetching and Clipboard operations">
|
||||
|
||||
<style>
|
||||
body { bg-[#f0fdf4] p-6 }
|
||||
h1 { text-[#059669] text-3xl font-bold text-center }
|
||||
h2 { text-[#047857] text-xl font-semibold }
|
||||
.container { bg-[#ffffff] p-6 rounded-lg shadow-lg max-w-4xl mx-auto }
|
||||
.button-group { flex gap-3 justify-center items-center flex-wrap }
|
||||
.clipboard-btn { bg-[#10b981] text-white hover:bg-[#059669] p-4 }
|
||||
.copy-url-btn { bg-[#8b5cf6] text-white hover:bg-[#7c3aed] }
|
||||
</style>
|
||||
|
||||
<script>
|
||||
gurt.log('Script started!')
|
||||
|
||||
local copyBtn = gurt.select('#copy-text-btn')
|
||||
|
||||
copyBtn:on('click', function()
|
||||
gurt.log('Copy button clicked!')
|
||||
Clipboard.write('Hello from GURT!')
|
||||
end)
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Clipboard API</h1>
|
||||
|
||||
<div style="container mt-6">
|
||||
<h2>Clipboard Operations</h2>
|
||||
<div style="button-group mb-6">
|
||||
<button id="copy-text-btn" style="action-button clipboard-btn">📋 Copy Text</button>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
""".to_utf8_buffer()
|
||||
|
||||
var HTML_CONTENTx = """<head>
|
||||
<title>Signal API Demo</title>
|
||||
<icon src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Lua-Logo.svg/256px-Lua-Logo.svg.png">
|
||||
<meta name="theme-color" content="#8b5cf6">
|
||||
|
||||
17
flumi/Scripts/Utils/Lua/Clipboard.gd
Normal file
17
flumi/Scripts/Utils/Lua/Clipboard.gd
Normal file
@@ -0,0 +1,17 @@
|
||||
class_name LuaClipboardUtils
|
||||
extends RefCounted
|
||||
|
||||
static func clipboard_write_handler(vm: LuauVM) -> int:
|
||||
var text: String = vm.luaL_checkstring(1)
|
||||
|
||||
DisplayServer.clipboard_set(text)
|
||||
|
||||
return 0
|
||||
|
||||
static func setup_clipboard_api(vm: LuauVM) -> void:
|
||||
vm.lua_newtable()
|
||||
|
||||
vm.lua_pushcallable(clipboard_write_handler, "Clipboard.write")
|
||||
vm.lua_setfield(-2, "write")
|
||||
|
||||
vm.lua_setglobal("Clipboard")
|
||||
1
flumi/Scripts/Utils/Lua/Clipboard.gd.uid
Normal file
1
flumi/Scripts/Utils/Lua/Clipboard.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dkfeh10fhve26
|
||||
@@ -33,6 +33,9 @@ static func setup_gurt_api(vm: LuauVM, lua_api, dom_parser: HTMLParser) -> void:
|
||||
# Setup Time API
|
||||
LuaTimeUtils.setup_time_api(vm)
|
||||
|
||||
# Setup Clipboard API
|
||||
LuaClipboardUtils.setup_clipboard_api(vm)
|
||||
|
||||
vm.lua_newtable()
|
||||
|
||||
vm.lua_pushcallable(LuaPrintUtils.lua_print, "gurt.log")
|
||||
|
||||
Reference in New Issue
Block a user