[][src]Crate artichoke_backend

artichoke-backend

artichoke-backend crate provides a Ruby interpreter. It currently is implemented with mruby bindings exported by the sys module.

Execute Ruby Code

artichoke-backend crate exposes several mechanisms for executing Ruby code on the interpreter.

Evaling Source Code

artichoke-backend crate exposes eval on the State with the Eval trait. Side effects from eval are persisted across invocations.

use artichoke_core::eval::Eval;
use artichoke_core::value::Value as _;

let interp = artichoke_backend::interpreter().unwrap();
let result = interp.eval(b"10 * 10").unwrap();
let result = result.try_into::<i64>();
assert_eq!(result, Ok(100));

Virtual Filesystem and Kernel#require

The artichoke-backend State embeds an in-memory virtual Unix filesystem. The VFS stores Ruby sources that are either pure Ruby, implemented with a Rust File, or both.

artichoke-backend crate implements Kernel#require and Kernel#require_relative which loads sources from the VFS. For Ruby sources, the source is loaded from the VFS as a Vec<u8> and evaled with Eval::eval_with_context. For Rust sources, File::require methods are stored as custom metadata on File nodes in the VFS.

Embed Rust Types in Ruby Values

Rust types that implement RustBackedValue can be injected into the interpreter as the backend for a Ruby object.

Examples of RustBackedValues include:

Converters Between Ruby and Rust Types

The convert module provides implementations for conversions between boxed Ruby values and native Rust types like i64 and HashMap<String, Option<Vec<u8>>> using an Artichoke interpreter.

License

artichoke-backend is licensed with the MIT License (c) Ryan Lopopolo.

Some portions of artichoke-backend are derived from mruby which is Copyright (c) 2019 mruby developers. mruby is licensed with the MIT License.

Some portions of artichoke-backend are derived from Ruby @ 2.6.3 which is copyright Yukihiro Matsumoto <matz@netlab.jp>. Ruby is licensed with the 2-clause BSDL License.

artichoke-backend vendors headers provided by emsdk which is Copyright (c) 2018 Emscripten authors. emsdk is licensed with the MIT/Expat License.

Modules

class
convert
def
eval
exception
exception_handler
extn
ffi

Functions for interacting directly with mruby structs from sys.

fs

Artichoke virtual filesystem used for storing Ruby sources.

gc
load
method
module
state
sys

Rust bindings for mruby, customized for Artichoke.

top_self
types
value
warn

Macros

mrb_get_args

Extract sys::mrb_values from a sys::mrb_state to adapt a C entrypoint to a Rust implementation of a Ruby function.

unwrap_interpreter

Extract an Artichoke instance from the userdata on a sys::mrb_state.

Structs

Artichoke

Interpreter instance.

BootError

Error returned when initializing an Artichoke interpreter.

Enums

ArtichokeError

Errors returned by Artichoke interpreters.

Functions

interpreter

Create and initialize an Artichoke interpreter.