Closed Zerim closed 6 years ago
This is done by calling invoke_export
on a module instance. Example.
This is done through Externals
and import resolvers that are passed to WASM functions as they are invoced from the Rust side. External functions can then do whatever they want but must return wasmi runtime values.
Arbitrarily complex, however, since WASM only supports ints/floats, this requires mapping complex data structures (such as vectors or hash maps) to the underlying memory. AssemblyScript does this and they provide implementations for typed arrays and maps.
This means we can safely use arrays and maps in mappings. However, if we want to pass data from Rust to WASM, we'll need to put it in memory in the exact same format, so WASM can interpret it. AssemblyScript bases its Map
implementation on two arrays (for keys and values); this kind of reuse could safe us some work.
Synchronous. You can call import Rust functions and call them but they have to return with a value immediately.
Yes. This can be done through import resolvers (on the Rust side) and imports (on the TS/WASM side).
[] What's the subset of TypeScript that is supported in WASM(i)? [] How do we call WASM functions from Rust? [] How do we call Rust functions from WASM? [] How complex and dynamic can data structures be that we pass back and forth between Rust and WASM? [] Is the foreign function interface provided by wasmi synchronous or asynchronous? [] Is there a way to define globals that are available to WASM functions/modules? [] How do we provide TypeScript types for the foreign function parameters, return values etc.?