From 2dfddee8c6fab6eb76cbfe3d95f7c30bfb870702 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 25 Sep 2026 21:53:00 -0300 Subject: sketchbook: what the game's review needed - input.started: true on the first update of a run, never after a reload, for a sketch to stop what should not resume from saved state. - A console line that errors fails its script. Sketch commands answer unknown, done or failed (abi.Outcome) instead of a bool that hid errors. - addScript also takes the hot-reloadable library, run through the generic host, so scripts can reload a real build. - Sounds that do not load are .none, not an empty clip. - sk_tag reads an enum field's tag name from the web build, for tests. --- src/abi.zig | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/abi.zig') diff --git a/src/abi.zig b/src/abi.zig index 3e23c47..4782599 100644 --- a/src/abi.zig +++ b/src/abi.zig @@ -106,6 +106,10 @@ pub const Input = struct { mode: Mode = .live, /// First frame after new code, or a new layout, was loaded. reloaded: bool = false, + /// First update since the program started (never after a hot reload): + /// the place to stop what should not resume from saved state, like a + /// song that was playing when the program quit. + started: bool = false, /// The console is open and owns the keyboard. console: bool = false, width: f32 = 0, @@ -366,8 +370,9 @@ pub const Host = struct { gpu: *const fn (*anyopaque) bool, /// Zero while unknown. imageSize: *const fn (*anyopaque, Image) [2]u32, + /// `.none` if the file does not load. loadSound: *const fn (*anyopaque, []const u8) Audio, - /// WAV bytes in memory. Not cached. + /// WAV bytes in memory. Not cached. `.none` if they do not decode. decodeSound: *const fn (*anyopaque, []const u8) Audio, /// The whole file, mapped for the life of the host; empty if missing. readFile: *const fn (*anyopaque, []const u8) []const u8, @@ -473,6 +478,15 @@ pub const Info = struct { pub const Memory = enum(u8) { state, session }; /// The entry points of a sketch, exported from libraries under these names. +/// What became of a console line offered to a sketch. +pub const Outcome = enum(u8) { + /// Not one of its commands. + unknown, + done, + /// It returned an error, already printed to the console. + failed, +}; + pub const Sketch = struct { info: *const fn () callconv(.c) *const Info, /// Declared default values, and nothing else. @@ -484,7 +498,7 @@ pub const Sketch = struct { /// Presentation: reads state, may change session, appends commands. draw: *const fn (*const Context, [*]const u8, [*]u8) callconv(.c) void, /// A console line the host did not understand; true when handled. - command: *const fn (*const Context, [*]u8, [*]u8, *const []const u8) callconv(.c) bool, + command: *const fn (*const Context, [*]u8, [*]u8, *const []const u8) callconv(.c) Outcome, pub const symbols = .{ .info = "sketch_info", -- cgit v1.3