Skip to content

Search documentation

Enter at least two characters.

    Practical SDK recipes

    SDK 0.1.0-preview.1 · ExperimentalDownload & release notes ↗

    These projects use SDK 0.1.0-preview.1. Download a project, extract it to a new directory, open the folder containing lui.json, select that exact SDK and run Check Types, then Run App. Save, Stop App and Run App after edits. Every download includes its full source, manifest, SDK pin and any required image bytes.

    Download the image project. The project contains a one-pixel PNG named Pixel.png, displayed as a dark square. Replace it with your own declared PNG or JPEG to show an application image or icon inside the UI.

    {
    "SchemaVersion": 2,
    "Script": "Src/Main.luau",
    "Capabilities": [],
    "Extensions": [],
    "Assets": [
    "Pixel.png"
    ],
    "ExtensionDeclarations": [],
    "Diagnostics": {
    "Mode": "Development"
    },
    "Modules": {
    "Root": "Src",
    "Files": [
    "Main.luau"
    ],
    "Requires": [],
    "Dependencies": []
    }
    }
    local Window = Instance.new("Window", {Title = "A bundled image", Size = UDim2.fromOffset(440, 240)})
    local Assets = app:GetService("AssetService")
    assert(Assets:Has("Pixel.png"), "Pixel.png must be declared")
    Instance.new("ImageLabel", {
    Parent = Window, Source = "Pixel.png",
    Position = UDim2.fromOffset(24, 24), Size = UDim2.fromOffset(96, 96),
    })
    Instance.new("TextLabel", {
    Parent = Window, Text = "The dark square is a declared PNG image.",
    Position = UDim2.fromOffset(24, 140), Size = UDim2.fromOffset(390, 50),
    })
    Window.Visible = true

    Assets declares files beside the manifest. ImageLabel.Source names that declaration. AssetService:Has checks the registered name; it is not a loader and does not prove decoding has succeeded. Decoding is asynchronous. Inputs are limited to 1 MiB encoded and 1,048,576 decoded pixels per image.

    Try a failure: rename Pixel.png without changing the manifest, then check/run again. The declared input is missing. Restore the name. If you change Source instead, ensure it exactly matches a declared name. Keep assets in the whole project and packaged app folder; do not send only the executable.

    Arbitrary disk paths, file:// paths and image URLs are not image sources. A file picker does not change that contract. This recipe uses a control image; it does not set a native window or tray icon. General disk loading and those icon properties require separate APIs.

    Download the time project. The first label shows UTC date/time. Wait a moment, click Update, and the second label shows elapsed milliseconds since this app opened.

    local Window = Instance.new("Window", {Title = "Time", Size = UDim2.fromOffset(480, 240)})
    local Performance = app:GetService("PerformanceService")
    local Started = Performance:GetTime()
    local Clock = Instance.new("TextLabel", {
    Parent = Window, Text = os.date("!%Y-%m-%d %H:%M:%S UTC"),
    Position = UDim2.fromOffset(24, 24), Size = UDim2.fromOffset(420, 44),
    })
    local Elapsed = Instance.new("TextLabel", {
    Parent = Window, Text = "Click Update to measure elapsed time.",
    Position = UDim2.fromOffset(24, 76), Size = UDim2.fromOffset(420, 44),
    })
    local Update = Instance.new("TextButton", {Parent = Window, Text = "Update", Position = UDim2.fromOffset(24, 140)})
    Update.Activated:Connect(function()
    Clock.Text = os.date("!%Y-%m-%d %H:%M:%S UTC")
    Elapsed.Text = tostring(math.floor(Performance:GetTime() - Started)) .. " ms since opening"
    end)
    Window.Visible = true

    The bundled Luau os library includes os.time, os.date, os.clock and os.difftime. os.time() returns wall-clock time in seconds; use os.date for formatting. The leading ! requests UTC. PerformanceService:GetTime() uses a steady clock in milliseconds with an unspecified origin; subtract two readings to measure elapsed time. Do not turn it into a calendar date.

    Try a failure: change os.time() in your own code to os.getenv("HOME"). Environment-variable access is unavailable; restore the supported call. os.path, io, package, arbitrary filesystem access and process/shell execution are also absent. Pure string manipulation is different from permission to read a native path. App-private storage is described in capabilities and the native storage contract.

    Download the right-click project. Right-click an empty part of the colored area, or activate Open menu using the keyboard. Choose the action to update the label. Press Escape while the menu choice is focused to dismiss it.

    local Window = Instance.new("Window", {Title = "Right-click input", Size = UDim2.fromOffset(520, 360)})
    local Surface = Instance.new("Frame", {
    Parent = Window, Position = UDim2.fromOffset(24, 24), Size = UDim2.fromOffset(460, 230),
    BackgroundColor3 = Color3.fromRGB(225, 235, 240),
    })
    local Status = Instance.new("TextLabel", {
    Parent = Surface, Text = "Right-click this area, or use Open menu.",
    Position = UDim2.fromOffset(12, 12), Size = UDim2.fromOffset(420, 40),
    })
    local Menu = Instance.new("Frame", {Parent = Surface, Visible = false, Size = UDim2.fromOffset(180, 48), ZIndex = 10})
    local Choice = Instance.new("TextButton", {Parent = Menu, Text = "Choose this action", Size = UDim2.fromOffset(180, 48)})
    local Open = Instance.new("TextButton", {Parent = Window, Text = "Open menu", Position = UDim2.fromOffset(24, 280)})
    local function ShowMenu(X: number, Y: number)
    Menu.Position = UDim2.fromOffset(math.clamp(X, 0, 280), math.clamp(Y, 0, 182))
    Menu.Visible = true
    Choice:Focus()
    end
    Surface.InputEnded:Connect(function(Input)
    if Input.Device == "Mouse" and Input.Button == "Right" and not Input.IsCanceled then
    ShowMenu(Input.Position.X, Input.Position.Y)
    end
    end)
    Open.Activated:Connect(function() ShowMenu(12, 64) end)
    Choice.Activated:Connect(function()
    Status.Text = "Action selected"
    Menu.Visible = false
    Open:Focus()
    end)
    Choice.InputBegan:Connect(function(Input)
    if Input.Device == "Keyboard" and Input.Key == "Escape" then
    Menu.Visible = false
    Open:Focus()
    end
    end)
    Window.Visible = true

    The event is a union. Check Device before reading pointer-only fields such as Button, Position and IsCanceled. Mouse beginnings/endings can identify Left, Right, Middle and auxiliary buttons; movement has no Button. Position is local to the target in logical units. This menu is a child of the clicked surface, so the example can use those local coordinates directly. A menu parented elsewhere needs an explicit coordinate conversion.

    The example opens on a completed right-button release and ignores cancellation. A canceled press must not activate an action. Multi-contact gestures must track both pointer and button identity; touch/pen events do not automatically mean “right click.” Native capture/focus mappings have platform-specific qualification limits.

    Try a recovery: open the menu, press Escape, then reopen it with the keyboard button. This is custom LUI application UI, not an OS context menu or global hotkey API. Its keyboard route and focus return are part of the example; broader accessibility/usability still needs real user testing.

    Download the HTTP project. It starts a loopback-only server on a selected free port. Click Send request. The label should become Hello from your local server. No external endpoint, account, raw socket grant or TLS credential is needed.

    {
    "SchemaVersion": 2,
    "Script": "Src/Main.luau",
    "Capabilities": [
    "network.client",
    "network.server"
    ],
    "Extensions": [],
    "Assets": [],
    "ExtensionDeclarations": [],
    "Diagnostics": {
    "Mode": "Development"
    },
    "Modules": {
    "Root": "Src",
    "Files": [
    "Main.luau"
    ],
    "Requires": [],
    "Dependencies": []
    },
    "NetworkPolicy": {
    "ClientLoopbackOnly": true,
    "ServerLoopbackOnly": true,
    "ClientPortMin": 0,
    "ClientPortMax": 0,
    "ServerPortMin": 0,
    "ServerPortMax": 0
    }
    }
    local Http = app:GetService("HttpService")
    local Server = app:GetService("HttpServerService"):CreateServer({Port = 0})
    Server:Route("GET", "/status", function(Request)
    return {StatusCode = 200, Body = "Hello from your local server"}
    end)
    Server:Start()
    local Window = Instance.new("Window", {Title = "Local HTTP", Size = UDim2.fromOffset(540, 240)})
    local Status = Instance.new("TextLabel", {
    Parent = Window, Text = "Click Send request. Port: " .. tostring(Server.Port),
    Position = UDim2.fromOffset(24, 24), Size = UDim2.fromOffset(480, 70),
    })
    local Send = Instance.new("TextButton", {Parent = Window, Text = "Send request", Position = UDim2.fromOffset(24, 120)})
    Send.Activated:Connect(function()
    task.spawn(function()
    local Ok, Response = pcall(function()
    return Http:RequestAsync({Url = "http://127.0.0.1:" .. tostring(Server.Port) .. "/status", TimeoutMs = 5000, MaxResponseBytes = 1024})
    end)
    if Window.IsClosed then return end
    if Ok then Status.Text = Response.Body else Status.Text = "Request failed. Check local host support and grants." end
    end)
    end)
    Window.Closed:Connect(function() Server:Close() end)
    Window.Visible = true

    HttpService needs network.client; HttpServerService needs network.server. The manifest’s explicit loopback policy keeps both directions local. The server binds before Start, and Port exposes the selected port. HTTP client calls yield, so this example runs them inside task.spawn. A normal HTTP error status is a response; transport, timeout, cancellation and policy failures can raise an error. Use StatusCode or Success when your application needs to distinguish response statuses.

    The app closes its server when its window closes; runtime destruction also retires owned work. A five-second request timeout and a 1 KiB response limit bound the example. An already-running request can fail if its server is closed; that is an expected application failure, not permission to retry forever.

    Try a failure: remove network.server from Capabilities, leaving the Luau unchanged. Check Types can still pass because it does not exercise the host grant. Run App should fail when it requests HttpServerService. Restore the token and rerun. The released editor may show only the generic exit described in capability troubleshooting; development SDKs provide the more specific reason.

    Inspect Layout refuses this privileged project. Use Run App. For HTTPS clients, the host verifies the peer; there is no verification bypass. Hosted TLS needs trusted host-supplied credentials, which the released stock CLI manifest does not load. See the released networking contract.