diff --git a/index.html b/index.html index dcbc2b9..5308ca9 100644 --- a/index.html +++ b/index.html @@ -196,7 +196,7 @@

Behavior packs

Plugins

-

Events, commands, custom content and services, in C++, C# or Java. Plugin API →

+

Events, commands, custom content and services, in C++, Java or WebAssembly. Plugin API →

diff --git a/plugins.html b/plugins.html index 69526e0..066a4c9 100644 --- a/plugins.html +++ b/plugins.html @@ -4,8 +4,8 @@ Plugins - Falcon - - + + @@ -16,7 +16,7 @@ - + @@ -24,7 +24,7 @@ - + @@ -52,14 +52,14 @@

Plugins for Falcon

- Extend the server with plugins written in C++, C# or Java. Every language sits on the same stable API, so a + Extend the server with plugins written in C++, Java or WebAssembly. Every language sits on the same stable API, so a plugin keeps working when the server updates.

API 1.2 C++17 - C# Java + WebAssembly Windows, Linux & macOS
@@ -73,6 +73,17 @@

Plugins for Falcon

Pick a runtime

+
+

WebAssembly New

+

Sandboxed plugins in any language with WIT bindings for core modules. The recommended choice for + new plugins: a broken or hostile plugin is stopped without taking the server down.

+
    +
  • No file system or network access
  • +
  • Memory capped by wasm-plugin-memory-mb, work per server call by + wasm-plugin-fuel
  • +
  • "runtime": "wasm"
  • +
+

Native C++ Available

Header-only C++ classes over a stable C ABI. Build with any compiler and the plugin loads on every @@ -94,8 +105,9 @@

Internal C++ Available

-

C# Available

-

.NET class libraries loaded in-process, with the same events, commands and content as C++.

+

C# Deprecated

+

.NET class libraries loaded in-process. Deprecated and removed in a future release: move to + WebAssembly, native C++ or Java.

  • Needs the .NET runtime
  • "runtime": "dotnet"
  • @@ -169,10 +181,12 @@

    Your first plugin

    -
    diff --git a/plugins.js b/plugins.js index a78514d..226fbd5 100644 --- a/plugins.js +++ b/plugins.js @@ -51,6 +51,52 @@ FALCON_PLUGIN(MyPlugin)` "main": "MyPlugin", "depend": [], "softdepend": [] +}` + } + ], + wasm: [ + { + title: "Build the module", + text: "Generate the C bindings from wasm/falcon.wit in the plugin SDK with " + + "wit-bindgen and build a core module with clang and a WASI sysroot. The server loads " + + "the core module, not a component.", + file: "build.sh", + syntax: "cmake", + code: `wit-bindgen c PluginAPI/wasm --out-dir build +clang --target=wasm32-wasip1 --sysroot="$WASI_SYSROOT" -mexec-model=reactor -O2 \\ + -Ibuild -IPluginAPI/wasm/c -o build/MyPlugin.wasm \\ + MyPlugin.c PluginAPI/wasm/c/falcon_wasm.c build/falcon_plugin.c build/falcon_plugin_component_type.o` + }, + { + title: "Write the plugin", + text: "Implement falcon_enable, subscribe to events and register commands. The " + + "falcon_wasm.h helper hides the bindings; everything else stays reachable through them.", + file: "MyPlugin.c", + syntax: "cpp", + code: `#include "falcon_wasm.h" + +static void welcome(void) { + falcon_player player; + if (falcon_event_player(&player)) + falcon_send(player, "Welcome!"); +} + +bool falcon_enable(void) { + falcon_on(FALCON_EVENT_PLAYER_JOIN, welcome); + return true; +}` + }, + { + title: "Install it", + text: "Put the module next to a plugin.json in plugins/MyPlugin/. It runs " + + "with no file system or network access.", + file: "plugin.json", + syntax: "json", + code: `{ + "name": "MyPlugin", + "version": "1.0.0", + "runtime": "wasm", + "main": "MyPlugin.wasm" }` } ], @@ -158,7 +204,8 @@ public class MyPlugin extends Plugin { const KEYWORDS = { cmake: ["include", "FetchContent_Declare", "FetchContent_MakeAvailable", "falcon_add_plugin"], - cpp: ["#include", "class", "public", "bool", "override", "return", "true", "false", "const", "auto"], + cpp: ["#include", "class", "public", "bool", "override", "return", "true", "false", "const", "auto", "static", + "void", "if"], csharp: ["using", "namespace", "public", "class", "override", "bool", "return", "true", "false"], java: ["package", "import", "public", "class", "extends", "boolean", "return", "true", "false", "@Override"], json: ["true", "false", "null"],