[−][src]Struct mruby::state::State
Fields
mrb: *mut mrb_statectx: *mut mrbc_contextvfs: MrbFilesystemnum_set_regexp_capture_globals: usizeMethods
impl State[src]
pub fn new(
mrb: *mut mrb_state,
ctx: *mut mrbc_context,
vfs: MrbFilesystem
) -> Self[src]
mrb: *mut mrb_state,
ctx: *mut mrbc_context,
vfs: MrbFilesystem
) -> Self
Create a new State from a sys::mrb_state and
sys::mrbc_context with an
in memory virtual filesystem.
pub fn close(self)[src]
Close a State and free underlying mruby structs and memory.
pub fn def_class<T: Any>(
&mut self,
name: &str,
enclosing_scope: Option<EnclosingRubyScope>,
free: Option<Free>
) -> Rc<RefCell<Spec>>[src]
&mut self,
name: &str,
enclosing_scope: Option<EnclosingRubyScope>,
free: Option<Free>
) -> Rc<RefCell<Spec>>
Create a class definition bound to a Rust type T. Class definitions
have the same lifetime as the State because the class def owns the
mrb_data_type for the type, which must be long-lived. Class defs are
stored by TypeId of T.
Internally, class::Specs are stored in an Rc<RefCell<_>> which
allows class specs to have multiple owners, such as being a super class
or an enclosing scope for a class or a module. To mutate the class spec,
call borrow_mut on the return value of this method to get a mutable
reference to the class spec.
Class specs can also be retrieved from the state after creation with
State::class_spec.
The recommended pattern for using def_class looks like this:
#[macro_use] extern crate mruby; use mruby::convert::FromMrb; use mruby::def::{ClassLike, Define}; use mruby::sys; use mruby::value::Value; extern "C" fn value(mrb: *mut sys::mrb_state, _slf: sys::mrb_value) -> sys::mrb_value { let interp = unsafe { unwrap_interpreter!(mrb) }; Value::from_mrb(&interp, 29).inner() } fn main() { let interp = mruby::interpreter().expect("mrb init"); let spec = { let mut api = interp.borrow_mut(); let spec = api.def_class::<()>("Container", None, None); spec.borrow_mut().add_method("value", value, sys::mrb_args_none()); spec.borrow_mut().add_self_method("value", value, sys::mrb_args_none()); spec.borrow_mut().mrb_value_is_rust_backed(true); spec }; spec.borrow().define(&interp).expect("class install"); }
pub fn class_spec<T: Any>(&self) -> Option<Rc<RefCell<Spec>>>[src]
Retrieve a class definition from the state bound to Rust type T.
This function returns None if type T has not had a class spec
registered for it using State::def_class.
Internally, class::Specs are stored in an Rc<RefCell<_>> which
allows class specs to have multiple owners, such as being a super class
or an enclosing scope for a class or a module. To mutate the class spec,
call borrow_mut on the return value of this method to get a mutable
reference to the class spec.
pub fn def_module<T: Any>(
&mut self,
name: &str,
enclosing_scope: Option<EnclosingRubyScope>
) -> Rc<RefCell<Spec>>[src]
&mut self,
name: &str,
enclosing_scope: Option<EnclosingRubyScope>
) -> Rc<RefCell<Spec>>
Create a module definition bound to a Rust type T. Module definitions
have the same lifetime as the State. Module defs are stored by
TypeId of T.
Internally, module::Specs are stored in an Rc<RefCell<_>> which
allows module specs to have multiple owners, such as being an enclosing
scope for a class or a module. To mutate the module spec, call
borrow_mut on the return value of this method to get a mutable
reference to the module spec.
Module specs can also be retrieved from the state after creation with
State::module_spec.
The recommended pattern for using def_module looks like this:
#[macro_use] extern crate mruby; use mruby::convert::FromMrb; use mruby::def::{ClassLike, Define}; use mruby::sys; use mruby::value::Value; extern "C" fn value(mrb: *mut sys::mrb_state, _slf: sys::mrb_value) -> sys::mrb_value { let interp = unsafe { unwrap_interpreter!(mrb) }; Value::from_mrb(&interp, 29).inner() } fn main() { let interp = mruby::interpreter().expect("mrb init"); let spec = { let mut api = interp.borrow_mut(); let spec = api.def_module::<()>("Container", None); spec.borrow_mut().add_method("value", value, sys::mrb_args_none()); spec.borrow_mut().add_self_method("value", value, sys::mrb_args_none()); spec }; spec.borrow().define(&interp).expect("class install"); }
pub fn module_spec<T: Any>(&self) -> Option<Rc<RefCell<Spec>>>[src]
Retrieve a module definition from the state bound to Rust type T.
This function returns None if type T has not had a class spec
registered for it using State::def_module.
Internally, module::Specs are stored in an Rc<RefCell<_>> which
allows module specs to have multiple owners, such as being an enclosing
scope for a class or a module. To mutate the module spec, call
borrow_mut on the return value of this method to get a mutable
reference to the module spec.
pub fn sym_intern(&mut self, sym: &str) -> mrb_sym[src]
Trait Implementations
Auto Trait Implementations
impl !Send for State
impl Unpin for State
impl !Sync for State
impl !UnwindSafe for State
impl !RefUnwindSafe for State
Blanket Implementations
impl<T> From<T> for T[src]
impl<T> ToString for T where
T: Display + ?Sized, [src]
T: Display + ?Sized,
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,