Class: Wasmtime::Global
- Inherits:
-
Object
- Object
- Wasmtime::Global
- Defined in:
- ext/src/ruby_api/global.rs
Overview
Represents a WebAssembly global.
Class Method Summary collapse
-
.const(store, type, default) ⇒ Global
A constant global.
-
.var(store, type, default:) ⇒ Global
A variable global.
Instance Method Summary collapse
- #const? ⇒ Boolean
-
#get ⇒ Object
The current value of the global.
-
#set(value) ⇒ nil
Sets the value of the global.
-
#type ⇒ Symbol
The Wasm type of the global‘s content.
- #var? ⇒ Boolean
Class Method Details
.const(store, type, default) ⇒ Global
Returns A constant global.
51 52 53 |
# File 'ext/src/ruby_api/global.rs', line 51
pub fn const_(store: Obj<Store>, value_type: Symbol, default: Value) -> Result<Self, Error> {
Self::new(store, value_type, default, Mutability::Const)
}
|
.var(store, type, default:) ⇒ Global
Returns A variable global.
61 62 63 |
# File 'ext/src/ruby_api/global.rs', line 61
pub fn var(store: Obj<Store>, value_type: Symbol, default: Value) -> Result<Self, Error> {
Self::new(store, value_type, default, Mutability::Var)
}
|
Instance Method Details
#const? ⇒ Boolean
98 99 100 |
# File 'ext/src/ruby_api/global.rs', line 98
pub fn is_const(&self) -> Result<bool, Error> {
self.ty().map(|ty| ty.mutability() == Mutability::Const)
}
|
#get ⇒ Object
Returns The current value of the global.
118 119 120 121 122 |
# File 'ext/src/ruby_api/global.rs', line 118
pub fn get(&self) -> Result<Value, Error> {
self.inner
.get(self.store.context_mut()?)
.to_ruby_value(&self.store)
}
|
#set(value) ⇒ nil
Sets the value of the global. Raises if the global is a const
.
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'ext/src/ruby_api/global.rs', line 129
pub fn set(&self, value: Value) -> Result<(), Error> {
self.inner
.set(
self.store.context_mut()?,
value.to_wasm_val(&self.value_type()?)?,
)
.map_err(|e| error!("{}", e))
.and_then(|result| {
self.retain_non_nil_extern_ref(value)?;
Ok(result)
})
}
|
#type ⇒ Symbol
Returns The Wasm type of the global‘s content.
112 113 114 |
# File 'ext/src/ruby_api/global.rs', line 112
pub fn type_(&self) -> Result<Symbol, Error> {
self.ty().map(|ty| ty.content().clone().to_sym())
}
|
#var? ⇒ Boolean
105 106 107 |
# File 'ext/src/ruby_api/global.rs', line 105
pub fn is_var(&self) -> Result<bool, Error> {
self.ty().map(|ty| ty.mutability() == Mutability::Var)
}
|