Pumpkin plugin API for Zig
Go to file
MegalithOfficial 60bb3cd429
Lift only the handled event in handle-event
The generated export lifted the whole Event variant, which pulls in code for
every event there is. A plugin now only compiles the cases it handles, the
example builds in about 6s instead of 75s.
2026-09-21 18:33:30 +02:00
.github/workflows Add CI and a workflow to sync the WIT submodule 2026-09-19 17:47:15 +02:00
example/src Add Zig bindings for the Pumpkin plugin API 2026-09-19 17:46:24 +02:00
src Lift only the handled event in handle-event 2026-09-21 18:33:30 +02:00
tools Add Zig bindings for the Pumpkin plugin API 2026-09-19 17:46:24 +02:00
wit@2366bb9edb Add Zig bindings for the Pumpkin plugin API 2026-09-19 17:46:24 +02:00
.gitignore Add Zig bindings for the Pumpkin plugin API 2026-09-19 17:46:24 +02:00
.gitmodules Add Zig bindings for the Pumpkin plugin API 2026-09-19 17:46:24 +02:00
build.zig Add Zig bindings for the Pumpkin plugin API 2026-09-19 17:46:24 +02:00
build.zig.zon Add Zig bindings for the Pumpkin plugin API 2026-09-19 17:46:24 +02:00
LICENSE-APACHE Add Zig bindings for the Pumpkin plugin API 2026-09-19 17:46:24 +02:00
LICENSE-MIT Add Zig bindings for the Pumpkin plugin API 2026-09-19 17:46:24 +02:00
README.md Add Zig bindings for the Pumpkin plugin API 2026-09-19 17:46:24 +02:00

Pumpkin API for Zig

This package provides Zig bindings for building Pumpkin plugins using WebAssembly (Wasm) components.

You will need Zig 0.16.0 and wasm-tools in your PATH.

Quick Start

  1. Setup Your Project

Add the package to your project:

zig fetch --save git+https://github.com/Pumpkin-MC/pumpkin-api-zig

Create a build.zig for your plugin:

const std = @import("std");
const pumpkin_api = @import("pumpkin_api_zig");

pub fn build(b: *std.Build) void {
    _ = pumpkin_api.addPlugin(b, b.dependency("pumpkin_api_zig", .{}), .{
        .name = "pumpkin-plugin-example",
        .root_source_file = b.path("src/main.zig"),
    });
}
  1. Write Your Plugin

Create your source file (e.g. src/main.zig):

const std = @import("std");
const pumpkin = @import("pumpkin");

pub const std_options: std.Options = .{ .logFn = pumpkin.logFn };

const MyPlugin = struct {
    pub const metadata: pumpkin.Metadata = .{
        .name = "pumpkin-plugin-example",
        .version = "0.1.0",
        .authors = &.{"You"},
        .description = "An example plugin in Zig.",
    };

    pub const events = .{
        .player_join_event = onJoin,
    };

    pub fn onLoad(_: pumpkin.Context) !void {
        std.log.info("Hello from Zig!", .{});
    }

    fn onJoin(_: pumpkin.Server, ev: *pumpkin.EventData(.player_join_event)) void {
        std.log.info("{s} joined", .{ev.player.getName()});
    }
};

comptime {
    pumpkin.register(MyPlugin);
}

Everything the API returns, handles included, is only valid until the current callback returns. Call keep() on a handle to hold on to it, then release it with deinit() when you're done.

  1. Build Your Plugin

Compile your plugin into a WebAssembly component:

zig build

This will produce zig-out/pumpkin-plugin-example.wasm ready to be loaded into Pumpkin.