/// Invoke an exported function from an instance.
Invoke an exported function from an instance.
Invoke an exported function from an instance .
fn invoke(
        &mut self,
        instance_name: Option<&str>,
        field: &str,
        args: &[wast::Expression],
    ) -> Result<Outcome> {
        let values = args.iter().map(runtime_value).collect::<Result<Vec<_>>>()?;
        let instance = self.get_instance(instance_name.as_ref().map(|x| &**x))?;
        let instance = instance.borrow();
        let export = instance
            .find_export_by_name(field)
            .ok_or_else(|| anyhow!("no global named `{}`", field))?;
        let func = match export {
            Extern::Func(f) => f.borrow(),
            _ => bail!("export of `{}` wasn't a global", field),
        };
        Ok(match func.call(&values) {
            Ok(result) => Outcome::Ok(result.into()),
            Err(e) => Outcome::Trap(e),
        })
    }
fn invoke ( & mut self , instance_name : Option < & str > , field : & str , args : & [ wast :: Expression ] , ) -> Result < Outcome > { let values = args . iter ( ) . map ( runtime_value ) . collect :: < Result < Vec < _ > > > ( ) ? ; let instance = self . get_instance ( instance_name . as_ref ( ) . map ( | x | & * * x ) ) ? ; let instance = instance . borrow ( ) ; let export = instance . find_export_by_name ( field ) . ok_or_else ( | | anyhow ! ( " " field ) ) ? ; let func = match export { Extern :: Func ( f ) => f . borrow ( ) , _ => bail ! ( " " field ) , } ; Ok ( match func . call ( & values ) { Ok ( result ) => Outcome :: Ok ( result . into ( ) ) , Err ( e ) => Outcome :: Trap ( e ) , } ) }
Invoke an exported function from an instance.
Invoke an exported function from an instance .
&mut self
instance_name
Option<&str>
field
&str
args
&[wast::Expression]