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.
85 86 87 |
# File 'ext/src/ruby_api/global.rs', line 85
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.
95 96 97 |
# File 'ext/src/ruby_api/global.rs', line 95
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
131 132 133 |
# File 'ext/src/ruby_api/global.rs', line 131
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.
151 152 153 154 155 |
# File 'ext/src/ruby_api/global.rs', line 151
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
.
162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'ext/src/ruby_api/global.rs', line 162
pub fn set(&self, value: Value) -> Result<(), Error> {
self.inner
.set(
self.store.context_mut()?,
value.to_wasm_val(&self.store, 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.
145 146 147 |
# File 'ext/src/ruby_api/global.rs', line 145
pub fn type_(&self) -> Result<Symbol, Error> {
self.ty()?.content().to_sym()
}
|
#var? ⇒ Boolean
138 139 140 |
# File 'ext/src/ruby_api/global.rs', line 138
pub fn is_var(&self) -> Result<bool, Error> {
self.ty().map(|ty| ty.mutability() == Mutability::Var)
}
|