54 lines
1.2 KiB
Markdown
54 lines
1.2 KiB
Markdown
# Script Runner WASM
|
|
|
|
A placeholder Rust script runner using wasm-bindgen.
|
|
|
|
## Building
|
|
|
|
```bash
|
|
# Install wasm-pack if not already installed
|
|
cargo install wasm-pack
|
|
|
|
# Build for web
|
|
npm run build
|
|
|
|
# Build for different targets
|
|
npm run build:nodejs # For Node.js
|
|
npm run build:bundler # For bundlers like webpack
|
|
npm run dev # Development build
|
|
```
|
|
|
|
## Usage
|
|
|
|
```javascript
|
|
import init, { ScriptRunner, greet, add } from './pkg/script_runner.js';
|
|
|
|
async function run() {
|
|
await init();
|
|
|
|
// Basic functions
|
|
greet("World");
|
|
console.log(add(1, 2)); // 3
|
|
|
|
// Script runner
|
|
const runner = new ScriptRunner();
|
|
runner.set_context("my_context");
|
|
console.log(runner.get_context()); // "my_context"
|
|
|
|
const result = runner.run_script("console.log('Hello from script')");
|
|
console.log(result);
|
|
|
|
// Evaluate expressions
|
|
console.log(runner.evaluate("hello")); // "Hello from Rust!"
|
|
console.log(runner.evaluate("version")); // "0.1.0"
|
|
}
|
|
|
|
run();
|
|
```
|
|
|
|
## Features
|
|
|
|
- Basic WASM initialization with panic hooks
|
|
- ScriptRunner class for managing execution context
|
|
- Simple expression evaluation
|
|
- Console logging integration
|
|
- Multiple build targets (web, nodejs, bundler) |