Plugin Block
High-performance custom logic compiled to WebAssembly (Rust, C++, Zig)
Open Plugin in BlockWerk →# Technical Manual: WASM Plugin Block (v4)
The WASM Plugin Block is the ultimate tool for high-performance simulation logic. It allows you to run native-speed models compiled from languages like Rust, C++, Zig, or Go directly within the BlockWerk engine.
🚀 Key Features
1. Native Simulation Performance
Unlike interpreted scripts, WASM plugins run at near-native CPU speeds. This makes them ideal for:
- 6-DOF physics models (drones, robots).
- Large-scale neural network estimators.
- High-frequency digital signal processing (DSP).
2. Standardized ABI (v1)
To integrate with BlockWerk, your WASM module should export a step function with the following signature:
- Inputs:
(t: f64, dt: f64, ...inputs: f64[]) - Output:
f64or a pointer to an array off64.
3. Dynamic Port Mapper
Easily map your WASM function arguments to the BlockWerk canvas:
- Each defined input in the Interface tab maps to a subsequent argument in your
stepfunction aftertanddt. - Each defined output maps to the return values of your
stepfunction.
🏗️ Getting Started
1. Compile your model: Ensure your language compiler targets wasm32-unknown-unknown (or wasm32-wasi with shim). 2. Expose the step function: #[no_mangle] pub extern "C" fn step(t: f64, dt: f64, in1: f64) -> f64 { ... } 3. Host the binary: Upload your .wasm file to a URL or your project assets. 4. Connect in BlockWerk: Provide the URL in the Plugin IDE and define your ports.
💡 Best Practices
- Memory Management: For complex models, manage states (integrators, delays) inside the WASM instance to avoid JS/WASM bridge overhead.
- Error Throttling: The BlockWerk UI will automatically throttle runtime errors from your plugin to maintain simulation stability.