#mruby #ruby #bindings #repl

mrusty

mruby safe bindings for Rust. Define and run Ruby without dependencies.

21 releases (1 stable)

Uses old Rust 2015

1.0.0 Dec 19, 2016
0.5.1 Apr 29, 2016
0.4.3 Apr 26, 2016
0.3.2 Apr 7, 2016
0.1.1 Feb 27, 2016

#5 in #bridge

Download history 8/week @ 2022-06-10 19/week @ 2022-06-17 11/week @ 2022-06-24 30/week @ 2022-07-01 26/week @ 2022-07-08 50/week @ 2022-07-15 28/week @ 2022-07-22 12/week @ 2022-07-29 22/week @ 2022-08-05 20/week @ 2022-08-12 33/week @ 2022-08-19 29/week @ 2022-08-26 17/week @ 2022-09-02 44/week @ 2022-09-09 14/week @ 2022-09-16 9/week @ 2022-09-23

86 downloads per month
Used in anima-engine

MPL-2.0 and maybe GPL

370KB
4.5K SLoC

Rust 4K SLoC // 0.0% comments Ruby 423 SLoC // 0.3% comments C 127 SLoC // 0.0% comments

mrusty. mruby safe bindings for Rust

[Build Status] (https://travis-ci.org/anima-engine/mrusty) [![Coverage Status] (https://coveralls.io/repos/github/anima-engine/mrusty/badge.svg?branch=master)] (https://coveralls.io/github/anima-engine/mrusty?branch=master) [Cargo Crate] (https://crates.io/crates/mrusty)

mrusty lets you:

  • run Ruby 1.9 files with a very restricted API (without having to install Ruby)
  • reflect Rust structs and enums in mruby and run them

It does all this in a safely neat way, while also bringing spec testing and a REPL to the table.

Documentation

Example

A very simple example of a Container struct which will be passed to mruby and which is perfectly callable.

// mrusty_class!
#[macro_use]
extern crate mrusty;

use mrusty::{Mruby, MrubyImpl};

let mruby = Mruby::new();

struct Cont {
    value: i32
}

// Cont should not flood the current namespace. We will add it with require.
mrusty_class!(Cont, "Container", {
    // Converts mruby types automatically & safely.
    def!("initialize", |v: i32| {
        Cont { value: v }
    });

    // Converts slf to Cont.
    def!("value", |mruby, slf: (&Cont)| {
        mruby.fixnum(slf.value)
    });
});

// Add file to the context, making it requirable.
mruby.def_file::<Cont>("cont");

// Add spec testing.
describe!(Cont, "
  context 'when containing 1' do
    it 'returns 1 when calling #value' do
      expect(Container.new(1).value).to eql 1
    end
  end
");

let result = mruby.run("
  require 'cont'

  Container.new(3).value
").unwrap(); // Returns Value.

println!("{}", result.to_i32().unwrap()); // Prints "3".

Dependencies

~0–1.2MB
~17K SLoC