Crates.io | plugger-ruby |
lib.rs | plugger-ruby |
version | 0.3.0 |
source | src |
created_at | 2016-05-15 15:07:36.529159 |
updated_at | 2017-10-18 05:37:46.32407 |
description | Ruby bindings to Plugger |
homepage | |
repository | https://github.com/dylanmckay/plugger |
max_upload_size | |
id | 5080 |
size | 13,355 |
Embed Ruby plugins directly into your Rust project!
Requires Rust nightly.
The purpose of this library is to allow scripting in your Rust projects as easy as possible.
The library itself consists of two main parts - a Ruby VM and a
syntax extension which creates Ruby wrappers over your struct
s and
impl
s so they can be used directly from Ruby.
It should be possible to simply annotate a type with #[pluggable]
and use
it directly from Ruby.
The thing that separates the library from the others is that it allows you to share your Rust code with Ruby, as opposed to writing Ruby objects in Rust.
eval
uating Ruby codeNOTE: Not everything here is supported yet. This is mostly automatic coercion between Rust and Ruby types.
Check tools/
for a working example.
struct Vector3(pub f64, pub f64, pub f64);
#[pluggable]
struct Player
{
name: String,
health: f32,
position: Vector3,
rotation: Vector3,
}
#[pluggable]
impl Player
{
pub fn revive(&mut self) { self.health = 1.0 }
pub fn rename(&mut self, name: &str) { self.name = name.to_owned() }
pub fn transport(&mut self, position: Vector3) { self.position = position; }
}
fn main() {
let mut vm = Ruby::new();
let player = Player { /* ... */ };
vm.plug("main_player", player);
vm.eval("main_player.revive").unwrap();
vm.eval("main_player.rename('foo')").unwrap();
}