ClipboardService
Capability-gated plain-text clipboard access through the host.
Required setup
Section titled “Required setup”Clipboard and a supported desktop clipboard. The supplied native runner installs its supported adapter.
The host is the program running your Luau code: normally the SDK’s native runner. Its provider/adapter implements an optional service. You do not need to write one to use a service already supplied by the SDK. Capabilities explains the manifest and remaining platform limits.
Example
Section titled “Example”Where to put it: replace Src/Main.luau in a project created with this SDK. This is the complete entry file.
Project setup: add Clipboard to Capabilities in lui.json. See the capability guide.
local Window = Instance.new("Window", { Title = "LUI example", Size = UDim2.fromOffset(560, 280),})local Status = Instance.new("TextLabel", { Parent = Window, Text = "Ready", Position = UDim2.fromOffset(16, 170), Size = UDim2.new(1, -32, 0, 72),})local Button = Instance.new("TextButton", { Parent = Window, Text = "Try it", Size = UDim2.fromOffset(220, 44), Position = UDim2.fromOffset(16, 16),})Button.Text = "Copy greeting"Button.Activated:Connect(function() local Clipboard = app:GetService("ClipboardService") if not Clipboard:WriteText("Hello from LUI") then Status.Text = "Copy failed"; return end Clipboard:ReadText(function(Text, Failure) Status.Text = if Failure then "Read failed" else "Clipboard: " .. (Text or "") end)end)Window.Visible = trueExpected result: Pressing the button copies a greeting and reads it back through a callback.
Methods
Section titled “Methods”WriteText
Section titled “WriteText”Writes plain text and returns whether the supported host accepted it.
WriteText(Text: string) -> booleanReadText
Section titled “ReadText”Calls back with text or an error. Handle failure in your app’s status UI; clipboard access is not unrestricted file access.
ReadText(Callback: (Text: string?, Error: string?) -> ()) -> ()Full type declaration — for type checking and deeper reference
The declaration is generated from the SDK. Self is supplied by a colon call; read means the field cannot be assigned. See how to read this reference.
export type ClipboardService = { read WriteText: (Self: ClipboardService, Text: string) -> boolean, read ReadText: (Self: ClipboardService, Callback: (Text: string?, Error: string?) -> ()) -> (),}Availability and deeper reading
Section titled “Availability and deeper reading”See platform limits before relying on host-specific behavior. The framework design specification and reflection/type sources are deeper engineering references, not extra setup required to build an app.