pumpkin-api-d/README.md
2026-09-16 22:06:45 -07:00

2.1 KiB

Pumpkin API for D

This package privdes D bindings for building Pumpkin plugins using WebAssembly (Wasm) components.

You will need LDC 1.43 or later as the compiler, with the addon-wasi package installed.

Quick Start

  1. Setup Your DUB Project

Create a dub.json configuration file for your plugin:

{
    "name": "pumpkin-plugin-example",
    "description": "A minimal Pumpkin plugin built with D.",
    "license": "proprietary",
    "authors": ["You"],
    "copyright": "Copyright © 2026, You",

    "dependencies": { "pumpkin-api-d": "~>0.1.0" },

    "targetType": "executable",
    "dflags": ["-Xcc=-mexec-model=reactor"],
    "buildTypes": {
        "debug": {
            "buildOptions": ["debugMode", "debugInfo"]
        },
        "release": {
            "buildOptions": ["optimize", "inline"],
            "dflags": ["-L-S"]
        }
    }
}
  1. Write Your Plugin

Create your source file in (e.g. source/plugin.d)

module plugin;

import wit.pumpkin.plugin.plugin;
import wit.common;
import pumpkin.register;

struct MyPlugin {
    @GetMetadata PluginMetadata getMetadata()
    {
        immutable(WitString)[$] authors = [
            "You".witList
        ];

        return (immutable PluginMetadata(
                name: "pumpkin-plugin-example".witList,
                version_: "0.1.0".witList,
                authors: authors.witList,
                description: "An example plugin in D.".witList,
                dependencies: WitList!WitString(),
                permissions: WitList!WitString()
        )).witClone;
    }

    @OnLoad
    Result!(void, WitString) onLoad(Context ctx)
    {
        scope(exit) ctx.witDrop; // incoming resources need to be cleaned up after they are done being used

        log(Level.info, "Hello from D!".witList);
        return ok!WitString;
    }
}

mixin RegisterPlugin!MyPlugin;
  1. Build Your Plugin

Compile your plugin into a WebAssembly component with DUB:

dub build -b release -a wasm32-wasip2

This will produce pumpkin-plugin-example.wasm in the project root ready to be loaded into Pumpkin.