Lua Runtime Overview¶
This section explains how EasyBar runs Lua widgets internally.
It is for contributors. For the public widget API, see Lua Widgets.
Overview¶
EasyBar does not embed Lua in-process.
It starts a separate Lua process and communicates with it over a dedicated Unix socket, while keeping stderr reserved for logs.
That gives the project:
- crash isolation
- simpler reloads
- clean widget state reset on restart
- plain JSON transport between Swift and Lua
- transport isolation from process logs
High-level flow¶
flowchart TD
Start["Swift starts the Lua runtime process"]
Load["Lua loads widget files"]
Subscriptions["Lua reports required driver events"]
Sources["Swift starts required native event sources"]
Events["Swift sends normalized events over the Lua socket"]
State["Lua updates widget state"]
Trees["Lua emits rendered trees"]
Store["Swift updates WidgetStore"]
Start --> Load
Load --> Subscriptions
Subscriptions --> Sources
Sources --> Events
Events --> State
State --> Trees
Trees --> Store
- Swift starts the Lua runtime process.
- Lua loads every widget file from the widget directory.
- Lua reports which driver events it needs.
- Swift starts only those event sources.
- Swift sends normalized events to Lua as JSON lines over the Lua socket.
EasyBarLuaRuntimeconnects that socket and then execs Lua, so the Lua runtime still speaks line I/O while Swift owns the socket lifecycle.- Lua updates widget state and emits rendered trees as JSON lines over that same socket.
- Swift decodes those trees and updates the UI store.
Main Swift pieces¶
LuaProcessController.swiftstarts and stops the Lua processLuaTransport.swiftowns the dedicated Lua socket plus stderr log handlingEasyBarLuaRuntimeconnects the configured Lua socket and then execs the Lua interpreterLuaLogBridge.swiftconverts structured Lua stderr lines into normal Swift logsLuaRuntime.swiftsmall facade over process and socket transportWidgetEngine.swiftowns the runtime handshake, subscriptions, and tree updatesEventHub.swiftsends app and widget events to both Swift listeners and LuaEventManager.swiftstarts only the native event sources Lua actually subscribed toRuntimeCoordinator.swiftowns startup, shutdown, reload, file watching, and socket-command orchestrationWidgetStore.swiftstores the latest rendered node trees
Main Lua pieces¶
runtime.luaruntime bootstrap and main loop over socket-backed stdin/stdoutloader.lualoads widget files into isolated environmentsapi.luapubliceasybarAPI, node handles, and registry bridgeregistry.luastores node state and applies property normalizationsubscriptions.luaowns node subscriptions and interval callbacksevents.luanormalizes raw payloads and dispatches themrender.luaconverts registry state into flat node treesjson.luasmall JSON encoder/decoderlog.luastructured stderr logging