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

Method start_func

crates/tinywasm/src/instance.rs:619–646  ·  view source on GitHub ↗

Get the start function of the module Returns None if the module has no start function If no start function is specified, also checks for a `_start` function in the exports ## Example ```rust # fn main() -> tinywasm::Result<()> { # use tinywasm::{ModuleInstance, Store}; # let wasm = wat::parse_str(r#" # (module # (func (export "_start")) # ) # "#).expect("valid wat"); # let module =

(&self, store: &Store)

Source from the content-addressed store, hash-verified

617 ///
618 /// See <https://webassembly.github.io/spec/core/syntax/modules.html#start-function>
619 pub fn start_func(&self, store: &Store) -> Result<Option<Function>> {
620 self.validate_store(store)?;
621
622 let func_addr = match self.0.func_start {
623 Some(func_index) => func_index,
624 None => {
625 // Alternatively, check for a _start function in the exports.
626 let Some(ExternVal::Func(func_addr)) = self.export_addr("_start") else {
627 return Ok(None);
628 };
629
630 return Ok(Some(Function {
631 item: crate::StoreItem::new(self.0.store_id, func_addr),
632 module_addr: self.id(),
633 addr: func_addr,
634 ty: store.state.get_func(func_addr).ty().clone(),
635 }));
636 }
637 };
638
639 let func_addr = self.resolve_func_addr(func_addr);
640 Ok(Some(Function {
641 item: crate::StoreItem::new(self.0.store_id, func_addr),
642 module_addr: self.id(),
643 addr: func_addr,
644 ty: store.state.get_func(func_addr).ty().clone(),
645 }))
646 }
647
648 /// Invoke the start function of the module
649 ///

Callers 2

runFunction · 0.80
startMethod · 0.80

Calls 6

export_addrMethod · 0.80
get_funcMethod · 0.80
resolve_func_addrMethod · 0.80
validate_storeMethod · 0.45
idMethod · 0.45
tyMethod · 0.45

Tested by

no test coverage detected