Commands
Optional app library · SDK 0.1.0-preview.2.
Keep actions in one registry so a button, palette and keyboard shortcut can invoke the same code. The registry does not draw a menu or palette for you.
From the extracted SDK folder, create a sibling app with ./lui.cmd new ../MyWorkbench --template workbench. Keep its Vendor files, lui.json, module lock and SDK pin together. See library setup.
Import require("@LuiWorkbench/Commands") after the project declares that library. An import copied into a basic starter is not enough.
Example
Section titled “Example”Replace Src/Main.luau in that prepared project with this complete file.
local Window = Instance.new("Window", {Title = "Library example", Size = UDim2.fromOffset(640, 300)})local Status = Instance.new("TextLabel", {Parent = Window, Text = "Ready", Position = UDim2.fromOffset(16, 190), Size = UDim2.fromOffset(600, 72)})local Commands = require("@LuiWorkbench/Commands")local Registry = Commands.New()Registry:Register({Id = "Greeting", Label = "Say hello", Execute = function() Status.Text = "Hello" end})local Button = Instance.new("TextButton", {Parent = Window, Text = "Say hello", Size = UDim2.fromOffset(220, 44)})Button.Activated:Connect(function() Registry:Execute("Greeting") end)Window.Destroying:Connect(function() Registry:Dispose() end)Window.Visible = trueExpected result: The button invokes a named action. You can invoke the same action from a palette or shortcut without duplicating the application callback.
Functions
Section titled “Functions”Commands.New(): RegistryBehavior and limits
Section titled “Behavior and limits”Commands.New() supports 128 commands. IDs are unique and at most 128 UTF-8
bytes; labels 256; categories 128; queries 256. Search matches every
whitespace-separated token in label/ID/category, case-insensitively for ASCII,
in stable ID order. List(Query?, Limit?) defaults to 12 rows, maximum 128.
Rows and copied shortcut bindings are immutable. A shortcut is an exact portable
Key plus optional Control/Shift/Alt booleans. Conflicting bindings are refused.
Definitions and bindings must be plain tables; metatables are refused. Only the
four validated shortcut fields are retained. Unregister handles retain an opaque
identity rather than callbacks, so holding one after disposal does not retain
the registered callback’s application data.
Enablement is checked again at execution. Predicates that fail disable the
command. Execute returns (Success, Reason?): Missing, Disabled, Busy, Retired,
or Failed. Application callback details are not returned or logged. Invocation
is serialized until its callback returns, including across scheduler yields.
Registration during an invocation and recursive listing are refused. Listing
from a command may build a palette without releasing the invocation fence.
Disposal and unregister remain available. Callbacks must finish or use existing cancellation-aware LUI
services. The registry does not own or cancel tasks started by a command.
Dispatch ignores repeats and every shortcut while TextEditing is true.
It uses the existing unhandled Window.Shortcut signal; it cannot consume native
input. Bind palette buttons and menus to Execute as well. Native shortcut
availability follows the host’s existing shortcut mapping. Dispose drops all
callbacks and rejects subsequent mutations; unsubscribe the window signal too.
Exported type declarations — advanced reference
These types describe returned models/controllers and their options. They are not additional classes to create.
Shortcut
Section titled “Shortcut”export type Shortcut = {read Key: string, read Control: boolean?, read Shift: boolean?, read Alt: boolean?}Command
Section titled “Command”export type Command = { read Id: string, read Label: string, read Category: string?, read Shortcut: Shortcut?, read Enabled: (() -> boolean)?, read Execute: () -> (),}export type Row = {read Id: string, read Label: string, read Category: string, read Enabled: boolean, read Shortcut: Shortcut?}Registry
Section titled “Registry”export type Registry = { Register: (Self: Registry, Definition: Command) -> (() -> ()), List: (Self: Registry, Query: string?, Limit: number?) -> {Row}, Execute: (Self: Registry, Id: string) -> (boolean, string?), Dispatch: (Self: Registry, Input: KeyboardShortcut) -> (boolean, string?), Dispose: (Self: Registry) -> (),}Deeper implementation reading
Section titled “Deeper implementation reading”The library source is useful when extending the framework or understanding cleanup. Private support modules such as Scope/State are implementation details, not additional supported app APIs.