summaryrefslogtreecommitdiff
path: root/src/kinds
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 22:49:11 -0300
committerGabriel Schneider <[email protected]>2026-11-06 23:38:31 -0300
commitc36e38e0a26f9bdef2892621b99390dedd35686d (patch)
treec5817e8f3be6c9a2c930bd0d3576752e5feef070 /src/kinds
parent227111c84a2945087abb4395daf63c7b23ba5bab (diff)
downloadpardes-c36e38e0a26f9bdef2892621b99390dedd35686d.tar.gz
pardes-c36e38e0a26f9bdef2892621b99390dedd35686d.zip
kinds #48, the export rule finished: every Zig kind declares `pub const pardes_addon = addon.ops(T)` and calls `addon.exportLib(&pardes_addon)` in a comptime block, which exports it only when the output is a library (Zig 0.17 analyses no `pub const` of a library's root and no comptime block of a type made in a generic function, so the export cannot live in `ops` alone: one comptime line in the kind is the spelling that works), and a pardes with kinds compiled in reads the declarations; image.zig's `pub export`, snake's and life's `export` go, no rename anywhere, and fake.c stays the loader's test, never compiled in
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/kinds')
-rw-r--r--src/kinds/addon.zig12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/kinds/addon.zig b/src/kinds/addon.zig
index f921768f..229cf639 100644
--- a/src/kinds/addon.zig
+++ b/src/kinds/addon.zig
@@ -22,8 +22,13 @@
//! as Allocators, `seed`, `say`, `job`, `cancel`, `look`, `text`, `exec`,
//! `select` and `found`. A body written is at most `body_max` bytes.
//!
-//! export const pardes_addon = addon.ops(Snake);
+//! pub const pardes_addon = addon.ops(Snake);
+//! comptime {
+//! addon.exportLib(&pardes_addon);
+//! }
//!
+//! The library's one export; a pardes with the kind compiled in reads the
+//! declaration instead (Addon.zig), so two kinds there never collide.
//! addons/snake/snake.zig, addons/life/life.zig and addons/image/image.zig
//! are the examples.
const std = @import("std");
@@ -231,6 +236,11 @@ fn span(p: [*c]const u8, n: u64) []const u8 {
return if (p == null) "" else p[0..n];
}
+/// `pardes_addon` exported, when built as a library alone.
+pub fn exportLib(comptime ops_: *const c.pa_ops) void {
+ if (@import("builtin").output_mode == .Lib) @export(ops_, .{ .name = "pardes_addon" });
+}
+
/// A kind's `pa_ops`: its head, and a C function for each of its own.
pub fn ops(comptime T: type) c.pa_ops {
const F = struct {