Skip to content

feat: OnEvent name form + Emit node + handler-struct codegen (RFC-PLUGIN-EVENTS phase 3) #12

@apotema

Description

@apotema

Phase 3 of RFC-PLUGIN-EVENTS. Tracker: flow-codegen#11.

Scope

The flow-codegen-side of the new OnEvent form, plus the new Emit node, plus the legacy converter.

flow_io.zig

  • Event.OnEvent gains name: ?[]const u8 = null. module/callback/params become optional. buildEvent accepts either form; both-set or neither-set is error.MalformedFlow.
  • Add NodeKind.Emit = struct { event: []const u8 }. buildNodeKind parses it; validate accepts it (codegen rejects unknown event names with a sourced diagnostic).
  • Round-trip the new fields through renderFlowJsonc / parseFlow.

codegen.zig

  • New-form OnEvent (renderEventEntry): resolve the dotted name through the assembler's comptime resolver (phase 1 surface). Reflect the payload's fields via @typeInfo(VariantType).@"struct".fields. Emit a FlowEventHandler struct with game_ptr: *anyopaque = undefined and a method body that is the existing flow lowering. Lift anyNodeNeedsEntity and Subflow rejections for new-form flows (game is in scope via downcast of game_ptr).
  • Legacy-form OnEvent: keep the current setup()/flowEvent/raw-slot path verbatim. Removed in phase 6.
  • Emit node: lower to game.emit(.{ .<qualified_tag> = .{ .field = pin, ... } });. Inputs are reflected payload fields; unwired field = error.DanglingPin.

Converter

Ship a legacy_onevent_to_name converter that rewrites legacy OnEvent blocks to the name form once module+callback resolve through the merged-union variant map. Parallel to the .flow.zon.flow.jsonc converter shipped by RFC-FLOWS-JSONC.

Success criteria

  • New-form OnEvent codegens a FlowEventHandler struct that is assignable into the GameHooks receiver tuple (phase 4 picks them up).
  • Emit lowers to a single game.emit statement; payload field types round-trip.
  • Legacy form codegens unchanged.
  • Unknown event name → sourced error.UnknownEvent (file + node id in the diagnostic).
  • Tests for new-form, legacy form, Emit node, unknown event, and the converter.

Blocked on

References

  • RFC: §7 (flow-codegen resolution), §8 (Emit node), §5 (game access via game_ptr).
  • Existing renderEventEntry: flow-codegen/src/codegen.zig:517-575.
  • v1 OnEvent: flow-codegen/src/flow_io.zig:60-66.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions