summaryrefslogtreecommitdiff
path: root/src/Addon.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Addon.zig')
-rw-r--r--src/Addon.zig21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/Addon.zig b/src/Addon.zig
index c6dca34b..5219f2b1 100644
--- a/src/Addon.zig
+++ b/src/Addon.zig
@@ -174,9 +174,25 @@ var found_words: [Kind.max_kinds][64]LoadedWord = undefined;
var found_text: [Kind.max_kinds][2][4096]u8 = undefined;
var nfound: usize = 0;
-/// Every library of the two directories, in name order each, the user's
-/// first. A library that crashed at its last load is listed, not loaded.
+/// 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.
+const compiled_in: []const *const Kind.Ops = if (@import("builtin_addons").on) &.{ &@import("image_addon").pardes_addon, &pardes_addon_pdf } else &.{};
+extern const pardes_addon_pdf: Kind.Ops;
+
+/// The addons compiled in, as if loaded (`builtin` their path); else every
+/// library of the two directories, in name order each, the user's first. A
+/// library that crashed at its last load is listed, not loaded.
pub fn scan() []const Loaded {
+ for (compiled_in) |ops| {
+ found[nfound] = loadedOf(ops, "builtin", @splat(0), &found_words[nfound]);
+ if (ops.init) |init| if (init(&Kind.api) != Kind.c.PA_OK) {
+ found[nfound].why = "refused: its init failed";
+ };
+ nfound += 1;
+ }
+ if (compiled_in.len > 0) return found[0..nfound];
var data_buf: [4096]u8 = undefined;
const data = dataDir(&data_buf);
const crashed = crashedPath(data);
@@ -491,6 +507,7 @@ pub fn run(p: *Pardes, id: usize, arg: ?[]const u8) void {
}
const k = p.kinds.byName(rest) orelse return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon {t}: no addon brought kind {s}", .{ op, rest }) catch takes);
const e = &p.kinds.kinds[k];
+ if (op == .reload and std.mem.eql(u8, e.path.slice(), "builtin")) return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon reload: {s} is built into this pardes", .{rest}) catch takes);
if (op == .reload) return p.emit(.{ .addon = .{ .op = .reload, .pane = @intCast(id), .arg = .from(e.path.slice()) } });
const n = openPanes(p, rest);
if (n > 0) return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon unload: {d} {s} pane{s} open", .{ n, rest, if (n == 1) " is" else "s are" }) catch takes);