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:



68
69
70
71
72
73
74
75
76
# File 'ext/src/ruby_api/caller.rs', line 68

pub fn export(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(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



81
82
83
84
85
86
# File 'ext/src/ruby_api/caller.rs', line 81

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



91
92
93
94
95
96
97
# File 'ext/src/ruby_api/caller.rs', line 91

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).



61
62
63
# File 'ext/src/ruby_api/caller.rs', line 61

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