README and example
This commit is contained in:
parent
95e041bfc3
commit
6e397e588e
86
README.md
Normal file
86
README.md
Normal file
@ -0,0 +1,86 @@
|
||||
# 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.
|
||||
18
example/.gitignore
vendored
Normal file
18
example/.gitignore
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
.dub
|
||||
docs.json
|
||||
__dummy.html
|
||||
docs/
|
||||
/pumpkin-plugin-example
|
||||
pumpkin-plugin-example.wasm
|
||||
pumpkin-plugin-example.so
|
||||
pumpkin-plugin-example.dylib
|
||||
pumpkin-plugin-example.dll
|
||||
libpumpkin-plugin-example.a
|
||||
pumpkin-plugin-example.a
|
||||
pumpkin-plugin-example.lib
|
||||
pumpkin-plugin-example-test-*
|
||||
*.exe
|
||||
*.pdb
|
||||
*.o
|
||||
*.obj
|
||||
*.lst
|
||||
21
example/dub.json
Normal file
21
example/dub.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"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"]
|
||||
}
|
||||
}
|
||||
}
|
||||
6
example/dub.selections.json
Normal file
6
example/dub.selections.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"fileVersion": 1,
|
||||
"versions": {
|
||||
"pumpkin-api-d": "0.1.0"
|
||||
}
|
||||
}
|
||||
35
example/source/app.d
Normal file
35
example/source/app.d
Normal file
@ -0,0 +1,35 @@
|
||||
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;
|
||||
Loading…
Reference in New Issue
Block a user