Struct ruru::VM [] [src]

pub struct VM;

Virtual Machine and helpers

Methods

impl VM
[src]

fn init()

Initializes Ruby virtual machine.

This function should ONLY be used if you write a standalone application which calls Ruby itself, for example:

  • Sidekiq-like background processing

  • Unicorn-like web server

In these cases it should be called before any interaction with Ruby.

If you write a library which is being connected to Ruby in runtime (e.g. some gem), this function should not be used.

Examples

use ruru::{Class, VM};

VM::init();

// VM started, able to use Ruby now
// ...

Class::new("SomeClass"); // etc

fn parse_arguments(argc: Argc, arguments: *const AnyObject) -> Vec<AnyObject>

Converts a pointer AnyObject array to Vec<AnyObject>.

This function is a helper for callbacks.

Later it will be moved to other struct, because it is not related to VM itself.

Examples

use ruru::types::Argc;
use ruru::{AnyObject, Boolean, Class, RString, VM};

#[no_mangle]
pub extern fn string_eq(argc: Argc, argv: *const AnyObject, itself: RString) -> Boolean {
    let argv = VM::parse_arguments(argc, argv);
    let other_string = argv[0].as_string();

    Boolean::new(itself.to_string() == other_string.to_string())
}

fn main() {
    Class::from_existing("String").define_method("==", string_eq);
}