pumpkin-api-zig/tools/testdata/expected/wit/host.zig
MegalithOfficial 28c3e929ca
Add Zig bindings for the Pumpkin plugin API
The bindings under src/wit are generated from the pumpkin-plugin-wit
submodule by tools/gen.zig. The canonical ABI is handled at comptime in
src/abi.zig, so plugins are plain wasm32-freestanding modules and only
need wasm-tools to become a component.

On top of that there is a small hand written layer: plugin registration,
typed event handlers, declarative commands (cmd), text components from
struct literals (msg) and std.log support.
2026-09-19 17:46:24 +02:00

70 lines
2.4 KiB
Zig

// Generated by tools/gen.zig, do not edit.
const abi = @import("../abi.zig");
const types = @import("types.zig");
pub const Point = types.Point;
pub const Color = types.Color;
pub const Shape = types.Shape;
pub const Access = types.Access;
pub const Canvas = enum(u32) {
_,
pub const resource_drop = &raw.@"[resource-drop]canvas";
pub fn init(width: u32, height: u32) Canvas {
return abi.call(raw.@"[constructor]canvas", Canvas, .{ width, height });
}
/// Opens a canvas stored on disk.
pub fn open(path: []const u8) abi.Result(Canvas, []const u8) {
return abi.call(raw.@"[static]canvas.open", abi.Result(Canvas, []const u8), .{path});
}
pub fn draw(self: Canvas, shape: Shape, at: Point, color: Color) void {
return abi.call(raw.@"[method]canvas.draw", void, .{ abi.borrow(self), shape, at, color });
}
/// Copies `other` on top of this canvas.
pub fn blend(self: Canvas, other: Canvas, types_: Access) void {
return abi.call(raw.@"[method]canvas.blend", void, .{ abi.borrow(self), abi.borrow(other), types_ });
}
pub fn name(self: Canvas) ?[]const u8 {
return abi.call(raw.@"[method]canvas.name", ?[]const u8, .{abi.borrow(self)});
}
/// Keeps the handle alive past the current callback. Release it with `deinit`.
pub fn keep(self: Canvas) void {
abi.keep(Canvas, self);
}
/// Releases the handle now instead of when the callback returns.
pub fn deinit(self: Canvas) void {
abi.drop(Canvas, self);
}
};
/// Shows the canvas and closes it.
///
/// Consumes `canvas`.
pub fn present(canvas: Canvas) u64 {
return abi.call(raw.present, u64, .{canvas});
}
pub fn log(message: []const u8) void {
return abi.call(raw.log, void, .{message});
}
const raw = struct {
extern "demo:gen/host@1.2.0" fn @"[constructor]canvas"(i32, i32) i32;
extern "demo:gen/host@1.2.0" fn @"[static]canvas.open"(i32, i32, i32) void;
extern "demo:gen/host@1.2.0" fn @"[method]canvas.draw"(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32) void;
extern "demo:gen/host@1.2.0" fn @"[method]canvas.blend"(i32, i32, i32) void;
extern "demo:gen/host@1.2.0" fn @"[method]canvas.name"(i32, i32) void;
extern "demo:gen/host@1.2.0" fn present(i32) i64;
extern "demo:gen/host@1.2.0" fn log(i32, i32) void;
extern "demo:gen/host@1.2.0" fn @"[resource-drop]canvas"(i32) void;
};