AssemblyScript's loader component to run and work with compiled WebAssembly modules, as a stand-alone module.
import load from "assemblyscript/loader";
load("path/to/module.wasm", {
imports: {
...
}
}).then(module => {
...
// i.e. call module.exports.main()
});-
load(file:
ArrayBuffer | Uint8Array | string, options:ILoadOptions):Promise<IModule>
Loads a WebAssembly module either from a buffer or from a file and returns a promise for anIModule. -
ILoadOptions
Options to set up the environment created byload.- initialMemory:
number
Initial size of the memory in 64kb pages. - maximumMemory:
number
Maximum size of the memory in 64kb pages. - imports:
{ [key: string]: any }
Import elements. Usually functions.
- initialMemory:
-
IModule
Common module interface as returned byload.- memory:
WebAssembly.Memory
A reference to the underlying memory instance. - imports:
{ [key: string]: any }
Imported elements. Usually functions. - exports:
{ [key: string]: any }
Exported elements. Usually functions. - S8:
Int8Array
An 8-bit signed integer view on the memory. - U8:
Uint8Array
An 8-bit unsigned integer view on the memory. - S16:
Int16Array
A 16-bit signed integer view on the memory. - U16:
Uint16Array
A 16-bit unsigned integer view on the memory. - S32:
Int32Array
A 32-bit signed integer view on the memory. - U32:
Uint32Array
A 32-bit unsigned integer view on the memory. - F32:
Float32Array
A 32-bit float view on the memory. - F64:
Float64Array
A 64-bit float view on the memory. - currentMemory():
number
Gets the current size of the memory in 64kb pages. - growMemory(numPages:
number):number
Grows the memory by the specified number of 64kb pages.
- memory:
Note that memory views (I8, U8, etc.) are updated when the module's memory grows, hence make sure to always access them directly on the module instance.