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

87 lines
2.1 KiB
Markdown

# Pumpkin API for D
This package privdes D bindings for building Pumpkin plugins using WebAssembly (Wasm) components.
You will need [LDC](https://github.com/ldc-developers/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:
```json
{
"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"]
}
}
}
```
2. Write Your Plugin
Create your source file in (e.g. `source/plugin.d`)
```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;
```
3. Build Your Plugin
Compile your plugin into a WebAssembly component with DUB:
```sh
dub build -b release -a wasm32-wasip2
```
This will produce `pumpkin-plugin-example.wasm` in the project root ready to be loaded into Pumpkin.