datumhue.app.spawn
functiondatumhue.app.spawn(options: app.SpawnAppOptions) -> AppSpawn a child app from inline code, a loaded package, or a resolved package_ref. Returns the child's App handle immediately. A UI child that no window manager has wrapped (wm.wrap_app) by the time its script starts opens in the window of its nearest ancestor that has one, the root app aside: its parent's (this app's, or that of the parent named), or past service apps, which have none, the UI app's above them; with no such ancestor it opens at the top level. There it sits over that app's ui.root but outside it, so that app's focus navigation and Back never reach its widgets, at x/y/width/height from the window's top-left or filling the window, clipped, moved, resized, minimized and stacked with it. A press in it focuses it, and a press in the window's own area focuses that app again; a Back nothing in it takes goes on to the frame around the window. A window manager that wraps it later lifts it into its frame. Given a host element, it lives in that element instead.
local stage = datumhue.ui.root:panel({ width = 320, height = 200 })
local clock = datumhue.app.spawn({
name = "clock",
code = [[datumhue.ui.root:label({ text = "12:00" })]],
host = stage,
})
clock:on_end(function(e)
print(e.reason) --> terminated
end)
datumhue.time.after(1, function()
stage:remove()
end)options app.SpawnAppOptions options 25 keys
| Key | Type | Default | Description |
|---|---|---|---|
| name | string | a package takes its manifest name, and inline code raises | App name. |
| code | string | the package or package_ref source | Inline Lua source. Mutually exclusive with package / package_ref. It compiles as source only, so a compiled chunk ends the child with a compile fault. |
| package | Package | the code or package_ref source | A loaded package bundle to run. Mutually exclusive with code / package_ref. A value that is not a handle is ignored. |
| package_ref | PackageRef | the code or package source | A catalog reference; the child arrives once resolved + downloaded. Mutually exclusive with code / package. |
| storage | "spawner" | "own" | inline code uses this app's storage identity, and a package has its own | Whose data a child spawned from inline code uses: this app's, or a set of its own. Raises with package or package_ref. |
| weight | number | 10 | The child's share of script running time when apps compete for it, relative to the other running apps' weights; must be > 0. |
| x | number | the child fills the window it opens in | Initial bounds x; set x/y/width/height together. |
| y | number | the child fills the window it opens in | Initial bounds y; set x/y/width/height together. |
| width | number | the child fills the window it opens in | Initial bounds width; set x/y/width/height together. |
| height | number | the child fills the window it opens in | Initial bounds height; set x/y/width/height together. |
| args | string[] | the child gets no arguments | Launch arguments passed to the child. |
| title | string | the app name | Window title for the child app. |
| dirs | table<string, Dir | app.PreopenEntry> | no directory is granted | Directories to grant, keyed by child-facing name; each value is a Dir handle or a {handle, mode} entry. |
| files | table<string, File | app.PreopenFileEntry> | no file is granted | Files to grant, keyed by child-facing name; each value is a File handle or a {handle, mode} entry. |
| data_mounts | table<string, DataMount> | no data mount is granted | Data mounts to grant, keyed by child-facing name. |
| http_mounts | table<string, HttpMount> | no HTTP mount is granted | HTTP mounts to grant, keyed by child-facing name. A child can only receive mounts the parent holds. |
| ingress_mounts | table<string, IngressMount> | no ingress mount is granted | Ingress mounts to grant, keyed by child-facing name. A child can only receive mounts the parent holds. |
| permissions | app.SpawnPermissions | no capability is granted | Capabilities to grant the child; narrowed against the parent's grants. |
| service | boolean | inline code runs as a UI app, and a package as its manifest says | Spawn headless; valid only with inline code. |
| chunk_name | string | pkg:@local/<name>/init.lua, from name | The name Lua gives the child's code wherever it shows a position: compile and runtime errors, error positions, the messages pcall returns, tracebacks and the child's fault. Used exactly as given: 1 to 59 bytes of UTF-8 with no control characters. It changes nothing else, not the app's name, title or data. Valid only with inline code. |
| max_steps | integer | no limit of the child's own: it takes the limit this app runs under, if any, and otherwise runs each job as long as it needs, a slice at a time | The most steps one stretch of the child's code may run without pausing. A stretch starts as its script, a callback, a timer or on_update starts, and ends when that returns, waits on a suspending call such as time.wait_frames, or yields. A step is about one Lua instruction, and a library or datumhue call a few; the same code counts the same steps on every device. The count is checked about every 4096 steps, so a stretch may run up to that many past the limit. Going over ends the child as crashed, with a steps fault, and pcall cannot catch it. datumhue.on_terminate and the finalizers run as the child ends are not counted. A child of a limited app runs under the lower of the two limits. |
| parent | App | the caller | The app to place the child under: the caller or one of its ancestors. |
| host | UiElement | the child opens in its nearest windowed ancestor's window, at x/y/width/height or filling it | An element of this app for a UI child of this app to live in. Its window fills the element's box inside any border and follows it as it moves, resizes, hides and shows; it is clipped by the element's ancestors, scrolls with an enclosing scroll container, and draws above the element's own children and under this app's popovers. A press in it focuses it; Tab and the arrow keys enter it at the element's place in this app's order and leave it past its first or last widget; a cancel request it leaves goes on to this app from the element. Window managers cannot wrap, move, resize or minimize it. Removing the element, or an element holding it, ends the child as terminated. Raises with x, y, width or height, with service = true or a service package, with a parent other than this app, and for an element that was removed, is another app's, is a window manager's frame or already holds an app that has not ended. A service app named by package_ref is known only once it arrives: it never starts, and ends as not_started. |
| on_print | fun(e: app.PrintEvent) | no default | Called with the lines the child prints, at most once a frame; valid only with inline code. The lines still go to the workstation's log. The callback keeps this app running until the child has ended and its last lines have arrived. |
| on_message | fun(e: app.MessageEvent) | no default | Called with the messages the child posts with app.post_message, at most once a frame, with every message since the last call; valid only with inline code. Each call for the child runs before this app's App:on_end callback for it. The callback keeps this app running until the child has ended and its last messages have arrived. |
In the guide: Messages, events and shared state Launch other apps Write a window manager or launcher