Skip to content

Search documentation

Enter at least two characters.

    StorageService

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

    Scoped app-private storage installed by a trusted host. Applications use bounded keys, not arbitrary native paths.

    Advanced app/host integration API. Useful for lower-level work; ordinary app authors can start with the app-building path. This is public API, not permission to access private toolkit objects.

    Storage and "Storage": {"ApplicationId": "com.example.notes"} in lui.json. The supplied preview.2 desktop runner provisions app-private storage. A copied/packaged project has a separate scope.

    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.

    Low-level public host protocol. In preview.2, add Storage.ApplicationId as shown below. Preview.1 needs a custom embedding host that installs the storage provider; its standard SDK cannot provision this scope.

    Where to put it: replace Src/Main.luau in a project created with this SDK. This is the complete entry file.

    Project setup: add Storage to Capabilities in lui.json. Also add "Storage": {"ApplicationId": "com.example.docs"}. 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 Storage = app:GetService("StorageService")
    Storage:Open(buffer.fromstring("example_note"), nil, function(_, Handle, Failure)
    if Failure or not Handle then Status.Text = "Storage unavailable"; return end
    Storage:Read(buffer.create(0), Handle, function(Bytes, _, ReadFailure)
    if ReadFailure then
    Status.Text = "Read failed"
    elseif Bytes then
    Status.Text = buffer.tostring(Bytes)
    else
    Status.Text = "No saved note yet"
    end
    Handle:Close()
    end)
    end)
    Window.Visible = true

    Expected result: Reads one app-private key and closes its handle. No saved key is distinct from an empty saved buffer.

    • This is a public but low-level callback/buffer interface. For ordinary preferences in preview.2, start with the Preferences source library instead.
    • Keys are app-private names, not paths. Storage is unencrypted; it is unsuitable for credentials. Raw files are bounded to 4 MiB each, 128 files and 64 MiB per scope.

    Opens an app-private key: pass its UTF-8 bytes and nil handle. Completion returns a NativeHandle or an error. A key is not a filesystem path.

    Open(Input: buffer, Handle: NativeHandle?, Complete: (buffer?, NativeHandle?, string?) -> (), Progress: ((buffer) -> ())?) -> NativeRequest

    Reads through an open key handle. Pass an empty input buffer. Completion returns bytes, nil for a missing key, or an error; an empty buffer is a present empty value.

    Read(Input: buffer, Handle: NativeHandle?, Complete: (buffer?, NativeHandle?, string?) -> (), Progress: ((buffer) -> ())?) -> NativeRequest

    Writes the supplied bytes through an open key handle. Completion reports success/failure. Cancellation racing a committed write does not promise rollback.

    Write(Input: buffer, Handle: NativeHandle?, Complete: (buffer?, NativeHandle?, string?) -> (), Progress: ((buffer) -> ())?) -> NativeRequest

    Removes content for an open key. Pass an empty input buffer; an already missing key is allowed.

    Remove(Input: buffer, Handle: NativeHandle?, Complete: (buffer?, NativeHandle?, string?) -> (), Progress: ((buffer) -> ())?) -> NativeRequest
    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 StorageService = {
    read Open: (Self: StorageService, Input: buffer, Handle: NativeHandle?, Complete: (buffer?, NativeHandle?, string?) -> (), Progress: ((buffer) -> ())?) -> NativeRequest,
    read Read: (Self: StorageService, Input: buffer, Handle: NativeHandle?, Complete: (buffer?, NativeHandle?, string?) -> (), Progress: ((buffer) -> ())?) -> NativeRequest,
    read Write: (Self: StorageService, Input: buffer, Handle: NativeHandle?, Complete: (buffer?, NativeHandle?, string?) -> (), Progress: ((buffer) -> ())?) -> NativeRequest,
    read Remove: (Self: StorageService, Input: buffer, Handle: NativeHandle?, Complete: (buffer?, NativeHandle?, string?) -> (), Progress: ((buffer) -> ())?) -> NativeRequest,
    }

    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.