| Crates.io | mrubyedge |
| lib.rs | mrubyedge |
| version | 1.0.19-rc1 |
| created_at | 2024-01-22 13:13:32.713513+00 |
| updated_at | 2026-01-13 15:11:48.960695+00 |
| description | mruby/edge is yet another mruby that is specialized for running on WASM |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1108763 |
| size | 402,344 |
A pure-Rust reimplementation of the mruby VM that keeps its core execution engine no_std-friendly while striving for behavioral compatibility with upstream mruby.
mruby/edge is an mruby-compatible virtual machine implementation written in Rust, specifically designed for WebAssembly environments and embedded systems. It aims to provide:
no_std core: Can run in environments without standard library support.mrb files) and Ruby source codeAdd this to your Cargo.toml:
[dependencies]
mrubyedge = "1.0"
Load and execute a precompiled *.mrb file produced by mrbc:
use mrubyedge::rite;
use mrubyedge::yamrb::vm;
// Bundle the compiled script at build time
const SCRIPT: &[u8] = include_bytes!("./examples/simple.mrb");
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut rite = rite::load(SCRIPT)?;
let mut vm = vm::VM::open(&mut rite);
let value = vm.run()?;
println!("{:?}", value);
Ok(())
}
You can also construct IREP (internal representation) structures directly:
use mrubyedge::yamrb::{op, vm, value::RSym};
use mrubyedge::rite::insn::{Fetched, OpCode};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let irep = vm::IREP {
__id: 0,
nlocals: 0,
nregs: 7,
rlen: 0,
code: vec![
op::Op { code: OpCode::LOADI_1, operand: Fetched::B(1), pos: 0, len: 2 },
op::Op { code: OpCode::LOADI_2, operand: Fetched::B(2), pos: 2, len: 2 },
op::Op { code: OpCode::ADD, operand: Fetched::B(1), pos: 4, len: 2 },
op::Op { code: OpCode::STOP, operand: Fetched::Z, pos: 6, len: 1 },
],
syms: vec![],
pool: Vec::new(),
reps: Vec::new(),
catch_target_pos: Vec::new(),
};
let mut vm = vm::VM::new_by_raw_irep(irep);
let value = vm.run()?;
println!("{:?}", value);
Ok(())
}
For a command-line interface to compile and run Ruby scripts, see mrubyedge-cli.
See the LICENSE file in the repository root.