MCPcopy Index your code
hub / github.com/explodingcamera/tinywasm / func_untyped

Method func_untyped

crates/tinywasm/src/instance.rs:416–433  ·  view source on GitHub ↗

Get a function export by name. ## Example ```rust # fn main() -> tinywasm::Result<()> { # use tinywasm::{ModuleInstance, Store}; # use tinywasm::types::WasmValue; # let wasm = wat::parse_str(r#" # (module # (func (export "add") (param i32 i32) (result i32) # local.get 0 # local.get 1 # i32.add)) # "#).expect("valid wat"); # let module = tinywasm::parse_bytes(&was

(&self, store: &Store, name: &str)

Source from the content-addressed store, hash-verified

414 ///
415 /// For typed access, see [`Self::func`].
416 pub fn func_untyped(&self, store: &Store, name: &str) -> Result<Function> {
417 self.validate_store(store)?;
418
419 let func_addr = match self.require_export(name)? {
420 ExternVal::Func(func_addr) => func_addr,
421 _ => {
422 cold_path();
423 return Err(Error::Other(format!("Export is not a function: {name}")));
424 }
425 };
426
427 Ok(Function {
428 item: crate::StoreItem::new(self.0.store_id, func_addr),
429 addr: func_addr,
430 module_addr: self.id(),
431 ty: store.state.get_func(func_addr).ty().clone(),
432 })
433 }
434
435 /// Get a function by its module-local index.
436 ///

Callers 6

exec_fn_instanceFunction · 0.80
runFunction · 0.80
funcMethod · 0.80
test_return_invalid_typeFunction · 0.80

Calls 5

require_exportMethod · 0.80
get_funcMethod · 0.80
validate_storeMethod · 0.45
idMethod · 0.45
tyMethod · 0.45

Tested by 3

test_return_invalid_typeFunction · 0.64