Files
minimax/rust/script-runner/README.md
2025-10-29 20:36:09 -07:00

1.2 KiB

Script Runner WASM

A placeholder Rust script runner using wasm-bindgen.

Building

# 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

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)