Lua Runtime Events¶
Events are the main data path from Swift into Lua.
1. Swift emits events¶
From EventHub.swift.
Each event:
- notifies Swift listeners
- is sent to Lua as JSON over the dedicated socket
2. Lua declares subscriptions¶
After loading widgets:
- Lua sends required events
- Swift enables only those
The subscription list can change at runtime.
For example, interval plus on_interval causes Lua to request the shared interval driver cadence it needs.
3. Initial events¶
Once Lua has published both its subscriptions and ready, WidgetEngine emits the currently subscribed initial event batch and then triggers one normal refresh pass.
This prevents empty UI on startup.
4. Manual refresh¶
Refresh events go through the same pipeline.
There is no special path.
5. Lua dispatch¶
Lua runtime:
- reads JSON line
- decodes it
- normalizes with
events.lua - dispatches through subscriptions
- renders dirty trees
End-to-end data flow¶
Complete runtime path from system event to UI:
- system event occurs, for example Wi-Fi change
- Swift event source emits through
EventHub - event is forwarded to Lua via socket JSON
- Lua normalizes and dispatches it
- widget handlers update registry state through node handles
- renderer builds a new tree
- Lua emits JSON tree via the same socket
- Swift decodes and applies it to
WidgetStore - Swift UI updates accordingly
Important properties:
- no shared memory between Swift and Lua
- all communication is JSON-based
- rendering is always derived, never incremental mutation