MCPcopy Index your code
hub / github.com/anima-engine/mrusty

github.com/anima-engine/mrusty @v1.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.0 ↗ · + Follow
375 symbols 852 edges 32 files 36 documented · 10%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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".

Extension points exported contracts — how you extend this code

ClassLike (Interface)
A `trait` which connects `Class` & `Module`. [2 implementers]
src/mruby.rs
ReadLine (Interface)
A `trait` which performs very basic readline utility. [1 implementers]
src/read_line.rs
MrubyFile (Interface)
A `trait` useful for organising Rust types into dynamic mruby files. # Examples ``` # use mrusty::Mruby; # use mrusty: [1 …
src/mruby.rs
MrubyImpl (Interface)
A `trait` used on `MrubyType` which implements mruby functionality. [1 implementers]
src/mruby.rs

Core symbols most depended-on inside this repo

clone
called by 98
src/mruby.rs
filename
called by 17
src/mruby.rs
to_str
called by 15
src/mruby.rs
class
called by 11
src/mruby.rs
new
called by 9
src/repl.rs
call
called by 5
src/mruby.rs
mrb_ext_get_ud
called by 4
src/mrb_ext.c
mrb_ext_set_instance_tt
called by 4
src/mrb_ext.c

Shape

Function 170
Method 158
Class 36
Enum 7
Interface 4

Languages

Rust71%
Ruby20%
C9%

Modules by API surface

src/tests/macros.rs78 symbols
src/mruby.rs75 symbols
src/tests/mruby_ffi.rs43 symbols
src/mrb_ext.c34 symbols
src/mruby_ffi.rs25 symbols
tests/api.rs12 symbols
src/spec/example.rb8 symbols
src/spec/context.rb8 symbols
src/spec/matchers/within.rb6 symbols
src/spec/matchers/compare.rb6 symbols
src/spec/matchers/truthy.rb5 symbols
src/spec/matchers/respond.rb5 symbols

For agents

$ claude mcp add mrusty \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact