summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addons/image/image.zig5
-rw-r--r--addons/life/life.zig5
-rw-r--r--addons/pdf/pdf.zig3
-rw-r--r--addons/snake/snake.zig5
-rw-r--r--docs/typ/reference.typ6
-rw-r--r--src/Addon.zig6
-rw-r--r--src/kinds/addon.zig12
7 files changed, 31 insertions, 11 deletions
diff --git a/addons/image/image.zig b/addons/image/image.zig
index 88ae1e2d..09b17ca7 100644
--- a/addons/image/image.zig
+++ b/addons/image/image.zig
@@ -89,7 +89,10 @@ pub const Image = struct {
}
};
-pub export const pardes_addon = addon.ops(Image);
+pub const pardes_addon = addon.ops(Image);
+comptime {
+ addon.exportLib(&pardes_addon);
+}
test "a job decodes a picture to its size and pixels, and one past max_dim is scaled to fit" {
var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
diff --git a/addons/life/life.zig b/addons/life/life.zig
index 2f459e07..278990f8 100644
--- a/addons/life/life.zig
+++ b/addons/life/life.zig
@@ -4,7 +4,10 @@
const std = @import("std");
const addon = @import("addon");
-export const pardes_addon = addon.ops(Life);
+pub const pardes_addon = addon.ops(Life);
+comptime {
+ addon.exportLib(&pardes_addon);
+}
const W = 32;
const H = 16;
diff --git a/addons/pdf/pdf.zig b/addons/pdf/pdf.zig
index 4704e7c7..45f1e22a 100644
--- a/addons/pdf/pdf.zig
+++ b/addons/pdf/pdf.zig
@@ -29,9 +29,8 @@ const m = @import("pdf_bridge");
const c = addon.c;
pub const pardes_addon = addon.ops(Pdf);
-// A library's one export; a static pardes reads the declaration (Addon.zig).
comptime {
- if (@import("builtin").output_mode == .Lib) @export(&pardes_addon, .{ .name = "pardes_addon" });
+ addon.exportLib(&pardes_addon);
}
const gap_px = 8; // between two pages of the strip
diff --git a/addons/snake/snake.zig b/addons/snake/snake.zig
index cdbf74d9..dab5846e 100644
--- a/addons/snake/snake.zig
+++ b/addons/snake/snake.zig
@@ -130,7 +130,10 @@ pub const Snake = extern struct {
pub const load = addon.loadBytes;
};
-export const pardes_addon = addon.ops(Snake);
+pub const pardes_addon = addon.ops(Snake);
+comptime {
+ addon.exportLib(&pardes_addon);
+}
test "it eats, grows a segment and a point, dies on the wall, and its record is its state" {
var s = std.mem.zeroInit(Snake, .{ .rng = 3 });
diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ
index db9cdb54..db090d24 100644
--- a/docs/typ/reference.typ
+++ b/docs/typ/reference.typ
@@ -983,8 +983,10 @@ Exec, a message, a new text pane, its selection) it is handed at load.
`addons/fake/fake.c` uses every function; a kind with only a head and
`paint` is a valid one. In Zig, `src/kinds/addon.zig` (over the same
header, and nothing of the core) makes the `pa_ops` from a struct of the
-functions a kind has (`export const pardes_addon = addon.ops(Snake);`),
-wrapping every function of the header and every call of `pa_api`: the
+functions a kind has (`pub const pardes_addon = addon.ops(Snake);`, and
+`addon.exportLib(&pardes_addon)` in a `comptime` block, which exports it
+from a library alone, so a pardes with kinds compiled in reads each one's
+declaration), wrapping every function of the header and every call of `pa_api`: the
pane's arena and pardes's heap as `std.mem.Allocator`s, typed keys, clicks
and views, a window to `put` text in (column first, where the header's
`pa_put` is row first), a deadline for `tick`, a `prefix` written after
diff --git a/src/Addon.zig b/src/Addon.zig
index 04cffcb9..209c761a 100644
--- a/src/Addon.zig
+++ b/src/Addon.zig
@@ -175,9 +175,9 @@ var found_text: [Kind.max_kinds][2][4096]u8 = undefined;
var nfound: usize = 0;
/// A static pardes's addons (`zig build static`), compiled in: the image
-/// addon's module and the PDF's C, its `pardes_addon` renamed. A static
-/// binary cannot dlopen, and macOS's loader has no memfd: this is how
-/// either has image and PDF panes.
+/// and pdf modules' `pardes_addon` declarations, which only a library
+/// exports. A static binary cannot dlopen, and macOS's loader has no
+/// memfd: this is how either has image and PDF panes.
const compiled_in: []const *const Kind.Ops = if (@import("builtin_addons").on) &.{ &@import("image_addon").pardes_addon, &@import("pdf_addon").pardes_addon } else &.{};
/// The addons compiled in, as if loaded (`builtin` their path); else every
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 {