Add bidirectional host bridge

This commit is contained in:
gem
2026-06-09 16:26:37 +08:00
parent 7b3c5cb0f5
commit 0d4fbd030c
17 changed files with 632 additions and 3 deletions

View File

@@ -92,6 +92,22 @@ Network results are delivered back to Lua through `on_event(event)`:
- `network_ws_error`: WebSocket connection or stream error.
- `network_ws_close`: WebSocket connection closed.
## Runtime host bridge
Flutter host apps may register a `RuntimeHostBridge` when creating `LuaGameWidget` or `FlameLuaGame`.
Lua-to-Flutter calls:
- `runtime.host_call({ id?, method, data? })`: async request. Result is delivered to Lua as `host_call_result` with `id`, `method`, `ok`, and either `result` or `error`.
- `runtime.host_notify({ method, data? })`: fire-and-forget notification to Flutter host code.
Flutter-to-Lua calls:
- `FlameLuaGame.notifyLua(method, data?)`: emits a `host_notify` event into Lua.
- `FlameLuaGame.callLua(method, data?, timeout?)`: emits a `host_call` event into Lua and waits for Lua to call `runtime.host_respond({ id, result?, error? })`.
Host bridge payloads must be JSON-like values: null, bool, number, string, list, or string-keyed map. Unsupported Dart objects are converted to strings.
## RuntimeCommand
Runtime commands request generic side effects owned by Dart/Flame.