The official kits for writing runtime plugins for Hammer:
WebAssembly modules that follow the Extism plugin convention, plus the
Hammer-specific import and exports described in hammer-editor's docs/CLIENT-PLUGINS.md.
| Directory | What |
|---|---|
c/include |
The C kit: hammer.h, on top of Extism's extism-pdk.h (BSD-3, see EXTISM-PDK-LICENSE); hammer_json.h, a JSON reader that needs no allocation; hammer_out.h for output, hammer_text.h for words, hammer_action.h for actions' requests and replies (messages, documents, and pages of fields and buttons), hammer_diagnose.h for checks underlined in the editor, hammer_progress for long actions, and hammer_test.h for native unit tests |
c/build.sh, c/test.sh |
Build C plugin directories into packages, and run their native unit tests |
rust/hammer |
The Rust kit: Hammer's imports, operations (typed, in ops), and the cache, with serde for JSON; action and diagnose types, an action's pages among them, progress, http requests to the hosts the manifest names, byte offsets, an optional getrandom backend, and a zeroing allocator for Wizer builds |
rust/tools/finish.py |
Makes a module built from crates written for the browser loadable by Hammer: drops wasm-bindgen's leftovers and checks the imports |
kotlin/hammer |
The Kotlin kit: typed requests and replies, an action's pages among them, typed operations (hammer.ops), the cache, and for JVM tests a fake Hammer and ActionDriver, which runs an action through its pages as Hammer does |
api/operations.json |
Hammer's operations as ops.list describes them, from which both kits' typed operations are generated: Kotlin's hammer.ops and Rust's hammer::ops |
kotlin/codegen |
The generator, with KotlinPoet for Kotlin. gradle :codegen:updateOperations refreshes the snapshot from hammer-editor (tools/dump-operations.sh) and regenerates; :codegen:checkOperations fails when the generated code is out of date |
kotlin/gradle-plugin |
The com.darkrockstudios.hammer.plugin Gradle plugin: sets up a plugin project and builds its .hammerplugin |
kotlin/hello |
One small example of each kind of plugin, which RECIPES.md walks through: an export, actions replying with a message, with a document (one with fields and progress, one picking a character), and with two pages carrying state, a text check, and a command |
tools/package.sh |
Packs a plugin directory and its built module into a .hammerplugin |
tools/pack-c.sh |
Packs the C kit into the tarball each release carries |
New to writing plugins? RECIPES.md has a hello-world version of each kind, in Kotlin. Hammer's own plugins, in hammer-plugins, are fuller examples in each language.
The Kotlin kit and its Gradle plugin are on Maven Central, the Rust kit on crates.io, and the C kit on
each GitHub release as
hammer-plugin-sdk-c-<version>.tar.gz. PUBLISHING.md has how releases work, and the plan
for the rest.
- C:
#include "hammer.h", and build with the tarball'sbuild.sh <plugin directory>(c/build.shhere), which putsinclude/on the include path and packs the directory'smanifest.toml,settings.toml,locales/, andresources/with the module.test.sh <plugin directory>builds and runs itstest.c. The C template is a working plugin to start from, with the headers vendored. - Rust: depend on
hammer-plugin-kit = "<version>"and writeuse hammer::…; build forwasm32-unknown-unknown, and pack the module withtools/package.sh. The Rust template is a working plugin to start from. - Kotlin: apply
id("com.darkrockstudios.hammer.plugin") version "<version>", withmavenCentral()among the repositories inpluginManagementanddependencyResolutionManagement; it addscom.darkrockstudios.hammer:hammer-plugin-kitat the same version, andgradle hammerPluginbuilds the package. RECIPES.md starts with a new plugin. To build against a checkout of this repo instead,includeBuild("../hammer-plugin-sdk/kotlin/gradle-plugin")underpluginManagementandincludeBuild("../hammer-plugin-sdk/kotlin"), and apply the plugin without a version.
- C: clang with the wasm32 target and lld (
sudo apt install clang lld).c/test.sh c/testsruns the kit's own tests. - Rust: rustup and
rustup target add wasm32-unknown-unknown, thencargo buildinrust/.cargo test --target x86_64-unknown-linux-gnu(or your machine's target) runs the kit's tests. - Kotlin: a JDK and any Gradle 9, then
kotlin/build.shfor the example's package (setGRADLEto a Gradle launcher ifgradleis not on the path).gradle jvmTestinkotlin/runs the kit's and the example's unit tests.
In Hammer on desktop: Settings, Plugins, Install plugin, pick the .hammerplugin, approve its
permissions, and restart Hammer.
MIT; see LICENSE. c/include/extism-pdk.h is Extism's, under BSD-3
(EXTISM-PDK-LICENSE).