inkpad_executor/
instance.rs

1//! Inkpad executor instance
2#[cfg(not(feature = "std"))]
3use crate::wasmi as e;
4#[cfg(feature = "std")]
5use crate::wasmtime as e;
6use crate::{builder::Builder, derive, Result, Value};
7
8/// Instance instance
9pub struct Instance<T>(e::Instance<T>);
10
11impl<T> Instance<T> {
12    /// Instantiate a module with the given env builder
13    pub fn new(code: &[u8], builder: &Builder<T>, state: &mut T) -> Result<Self> {
14        Ok(Instance(<e::Instance<T> as derive::Instance<T>>::new(
15            code, builder, state,
16        )?))
17    }
18
19    /// invoke an exported function
20    pub fn invoke(&mut self, name: &str, args: &[Value], state: &mut T) -> Result<Value> {
21        derive::Instance::invoke(&mut self.0, name, args, state)
22    }
23
24    /// Get global value
25    pub fn get_global_val(&self, name: &str) -> Option<Value> {
26        derive::Instance::get_global_val(&self.0, name)
27    }
28}