Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anima-engine/mrusty
mruby safe bindings for Rust
https://github.com/anima-engine/mrusty
bridge mruby ruby rust
Last synced: 2 days ago
JSON representation
mruby safe bindings for Rust
- Host: GitHub
- URL: https://github.com/anima-engine/mrusty
- Owner: anima-engine
- License: mpl-2.0
- Created: 2016-02-05T12:55:22.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-08-13T12:32:59.000Z (over 3 years ago)
- Last Synced: 2024-12-07T22:48:17.870Z (about 1 month ago)
- Topics: bridge, mruby, ruby, rust
- Language: Rust
- Homepage:
- Size: 598 KB
- Stars: 205
- Watchers: 10
- Forks: 19
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rust-cn - anima-engine/mrusty - ci.org/anima-engine/mrusty.svg?branch=master">](https://travis-ci.org/anima-engine/mrusty) (Development tools / FFI)
- awesome-rust - anima-engine/mrusty - ci.org/anima-engine/mrusty.svg?branch=master">](https://travis-ci.org/anima-engine/mrusty) (Development tools / FFI)
- awesome-rust - anima-engine/mrusty
- awesome-rust-cn - anima-engine/mrusty
- awesome-rust-zh - anima-engine/mrusty - Rust 的 mruby 安全绑定 [<img src="https://api.travis-ci.org/anima-engine/mrusty.svg?branch=master">](https://travis-ci.org/anima-engine/mrusty) (开发工具 / FFI)
- awesome-rust - anima-engine/mrusty - mruby safe bindings for Rust (Development tools / FFI)
- awesome-rust - anima-engine/mrusty - ci.org/anima-engine/mrusty.svg?branch=master">](https://travis-ci.org/anima-engine/mrusty) (开发工具 Development tools / 示例 FFI)
- fucking-awesome-rust - anima-engine/mrusty - mruby safe bindings for Rust (Development tools / FFI)
- fucking-awesome-rust - anima-engine/mrusty - mruby safe bindings for Rust (Development tools / FFI)
README
# mrusty. mruby safe bindings for Rust
[![Build Status](https://travis-ci.org/anima-engine/mrusty.svg?branch=master)](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](http://meritbadge.herokuapp.com/mrusty)](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 `struct`s and `enum`s in mruby and run themIt does all this in a safely neat way, while also bringing spec testing and a
REPL to the table.## [Documentation](http://anima-engine.github.io/mrusty/)
## Example
A very simple example of a Container `struct` which will be passed to mruby and
which is perfectly callable.
```rust
// 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");// 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".
```