Class: Wasmtime::Caller

Inherits:
Object
  • Object
show all
Defined in:
ext/src/ruby_api/caller.rs

Overview

Represents the Caller’s context within a Func execution. An instance of Caller is sent as the first parameter to Func’s implementation (the block argument in Func.new).

Instance Method Summary collapse

Instance Method Details

#export(name) ⇒ Object

See Also:



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'ext/src/ruby_api/caller.rs', line 72

pub fn export(
    ruby: &Ruby,
    rb_self: Obj<Caller<'a>>,
    name: RString,
) -> Result<Option<Extern<'a>>, Error> {
    let inner = rb_self.handle.get_mut()?;

    if let Some(export) = inner.get_export(unsafe { name.as_str() }?) {
        export.wrap_wasmtime_type(ruby, rb_self.into()).map(Some)
    } else {
        Ok(None)
    }
}

#get_fuelInteger

Returns the amount of fuel in the Store.

Returns:

  • (Integer)

Raises:

  • (Error)

    if fuel consumption is not enabled via Engine#new



89
90
91
92
93
94
# File 'ext/src/ruby_api/caller.rs', line 89

pub fn get_fuel(&self) -> Result<u64, Error> {
    self.handle
        .get()
        .map(|c| c.get_fuel())?
        .map_err(|e| error!("{}", e))
}

#set_fuel(fuel) ⇒ Object

Sets fuel to the Store.

Parameters:

  • fuel (Integer)

    The new fuel amount.

Raises:

  • (Error)

    if fuel consumption is not enabled via Engine#new



99
100
101
102
103
104
105
# File 'ext/src/ruby_api/caller.rs', line 99

pub fn set_fuel(&self, fuel: u64) -> Result<(), Error> {
    self.handle
        .get_mut()
        .and_then(|c| c.set_fuel(fuel).map_err(|e| error!("{}", e)))?;

    Ok(())
}

#store_dataObject

Returns the store’s data. Akin to Store#data.

Returns:

  • (Object)

    The store’s data (the object passed to Store.new).



65
66
67
# File 'ext/src/ruby_api/caller.rs', line 65

pub fn store_data(&self) -> Result<Value, Error> {
    self.context().map(|ctx| ctx.data().user_data())
}