feat: engine lifecycle events on the bus with Lua events.subscribe#54
Merged
Conversation
…case event names Adds LuaEventBusForwarder (subscribes to the IEvent catch-all channel and forwards every event to the Lua bridge as snake_case names with snake_case payload keys), the events.subscribe function alongside events.on, a RegisterLuaEvents() registration helper, and serialized closure invocation in the bridge (bus events arrive on arbitrary threads).
…scriptions Also demos events.subscribe in the ScriptingLua sample and documents the snake_case event naming convention.
|
|
||
| Assert.Equal("MyApp:5:true", script.Globals.Get("captured").String); | ||
|
|
||
| forwarder.Dispose(); |
|
|
||
| Assert.Equal(200, (int)script.Globals.Get("counter").Number); | ||
|
|
||
| forwarder.Dispose(); |
Comment on lines
+87
to
+91
| catch (Exception ex) | ||
| { | ||
| Log.ForContext<LuaEventBusForwarder>() | ||
| .Warning(ex, "Failed to forward event {EventType} to Lua", eventData.GetType().Name); | ||
| } |
Comment on lines
+335
to
+338
| catch (Exception ex) | ||
| { | ||
| logger.Warning(ex, "EngineStoppedEvent publish failed"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three pieces, one flow: the bootstrap emits lifecycle events, Lua scripts consume them by name.
Engine events (bootstrap)
EngineStartingEvent(Application),EngineStartedEvent(Application, ServiceCount, ElapsedMs),EngineStoppedEvent(Application)- published on the event bus when one is registered (guarded; the empty bootstrap is unaffected; a failing stop-publish only warns).EngineStartingEventfires before the service loop, so only manual pre-start subscriptions see it (documented).Lua:
events.subscribe+ catch-all forwarderEventsuffix, snake_case (EngineStartedEvent->engine_started); payload keys snake_case. Applies to EVERY bus event.LuaEventBusForwardersubscribes to theIEventcatch-all channel (already supported by the bus) and forwards to the existing Lua bridge; optional-bus ctor = no-op without a bus; a broken script never fails bus dispatch.RegisterLuaEvents()wires bridge +eventsmodule + forwarder in one call;events.onstays as alias.LuaEventBridgenow serializes closure invocations (bus events arrive on arbitrary threads; MoonSharp is not thread-safe). Reentrancy-safe (System.Threading.Lock) for nested publishes.Template + sample + docs
squidstd-hosttemplate:OnConfigLoaded/OnConfigReadyexamples + C# subscriptions to the engine events (scratch-built against local sources: 0 errors).lua saw engine_stopped for SquidStd.Samples.ScriptingLuaafter shutdown.Test Plan