zinput.module
This package holds more than this page lists. See all of its files in its world.
README.md
autoTick
Opt-in tick loop for zinput. Spawns a task.spawnSystem worker that
invokes a registered tick function (Zin.tick) once per frame while the
input layer has work, and waits for the input layer's next change
(__waitChange("input"): an input event, a moved input snapshot, an
armed observation, a mapping-layer mark) once a tick finds it at rest
(Zin.atRest()), so code-mode snippets and tests without a host script
component still drive the stateful subsystems — live binding dispatch, the touch overlay, the
emulation floor, axes, chords, rebind, action handlers, event subscribers.
task.spawnSystem (not task.spawn) makes the loop system-owned, so it
keeps ticking while the editor pauses gameplay.
The first real input read arms this worker on its own. A host script
component can also call Zin.tick(dt) from its update(dt) hook, and
autoTick.start can be called directly; all three are idempotent
alongside each other.
Exports
M.start() -> boolean— spawn the worker unless one runs thatstop()has not been asked of. Returns true when a new loop was started; after astop(), or once the last worker has ended, it starts one at once.M.stop()— let the loop exit on its next yield. No-op if not running.M.isRunning() -> boolean— whether the worker's task is live: true fromstart()until the worker has ended, however it ended (stopped, raised, cancelled).M._setTickFn(fn: (number?) -> ())— internal hook. Called once byzinput/init.luauto registerZin.tick.M._setLastTickFrameIdFn(fn: () -> number)— internal hook. Wires the frame-id accessor so the worker can dedup itself against explicit ticks within the same engine frame.M._setAtRestFn(fn: () -> boolean)— internal hook. WiresZin.atRest, the predicate the worker reads after each tick to decide whether to wait for the input layer's next change.
Usage
local Zin = require("@builtin::modules.zinput")
-- One-shot test / code-mode setup:
Zin.autoTick.start()
-- ... later ...
Zin.autoTick.stop()
Notes
- Single-flight: calling
start()twice is a no-op — there is at most one worker per VM thatstop()has not been asked of. - Cross-coroutine dedup: when an explicit
Zin.tickran in the same engine frame, the worker skips that frame soonHeldhandlers and event subscribers don't double-fire. - Liveness is read from the worker's own task (
task.status), and each worker runs under a token of its own thatstop()lets go of. A worker that has ended reads not running whatever the module's memory holds: after a test hand-back writes module memory back, after a worker raised, and aftertask.cancelended it,isRunning()is false andstart()starts a new one. start()raises if_setTickFnhasn't been wired yet — alwaysrequire("@builtin::modules.zinput")first.