StorageService
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.
Required setup
Section titled “Required setup”Storage and a custom embedding host that explicitly installs app-private storage. The standard preview.1 project runner does not support Storage.ApplicationId. Do not copy a preview.2 storage manifest into preview.1.
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”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. This example requires a custom host that installs storage; the ordinary preview.1 runner cannot provision it. 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 = trueExpected result: Reads one app-private key and closes its handle. No saved key is distinct from an empty saved buffer.
Behavior and limits
Section titled “Behavior and limits”- 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.
Methods
Section titled “Methods”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) -> ())?) -> NativeRequestReads 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) -> ())?) -> NativeRequestWrites 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) -> ())?) -> NativeRequestRemove
Section titled “Remove”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) -> ())?) -> NativeRequestFull 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,}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.