Tour de WebAssembly Table des Matières

[Untranslated] Calling Functions

When we later want to call our dynamic function, we'll need some sort of invocation function that can take in our function handle and arguments.

Again, since WebAssembly can only pass back and forth numbers, and since all numbers in JavaScript are 64-bit floats, what this will look like ultimately is an imported function:

js_invoke_with_2_params(fn_handle:f64, a:f64, b:f64) -> f64

Putting it all together we

let log_handle = register_function("
  (param_a, param_b) => {
    // somehow call console_log  
  }");

let msg = "hello world";

js_invoke_with_2_params( log_handle,msg.as_ptr() as f64, 
    msg.len() as f64 );

You'll notice there is a problem with our JavaScript function though. It has the start and end of our utf-8 but not memory!

Mascot Ferris