~tim/scheme-vm

6f325e04c5c5c20942580e71c85c03b7ec6f1519 — Tim Morgan 4 years ago 252f654
Experiment with Rust extension
4 files changed, 39 insertions(+), 0 deletions(-)

M .gitignore
A Cargo.toml
A src/lib.rs
A test.rb
M .gitignore => .gitignore +2 -0
@@ 1,1 1,3 @@
.bundle
target
Cargo.lock

A Cargo.toml => Cargo.toml +10 -0
@@ 0,0 1,10 @@
[package]
name = "scheme-vm"
version = "0.1.0"
authors = ["Tim Morgan <tim@timmorgan.org>"]

[dependencies]
ruru = "0.9.0"

[lib]
crate-type = ["dylib"]

A src/lib.rs => src/lib.rs +20 -0
@@ 0,0 1,20 @@
#[macro_use]
extern crate ruru;

use ruru::{Boolean, Class, Object, RString};

methods!(
   RString,
   itself,

   fn string_is_weird() -> Boolean {
       Boolean::new(false)
   }
);

#[no_mangle]
pub extern fn initialize_string() {
    Class::from_existing("String").define(|itself| {
        itself.def("weird?", string_is_weird);
    });
}

A test.rb => test.rb +7 -0
@@ 0,0 1,7 @@
require 'fiddle'

library = Fiddle::dlopen('target/release/libscheme_vm.dylib')

Fiddle::Function.new(library['initialize_string'], [], Fiddle::TYPE_VOIDP).call

p ''.weird?