(export...)
Exports an object to JavaScript. You can export many different types of objects. You can only export one object per (export...)
S-Expression.
You can either add the export S-Expression within the object that is being exported, or create an S-Expression on its own that points to the object being exported.
Syntax
(global... (export propertyName) )
(memory... (export propertyName) )
(func... (export propertyName) )
(table... (export propertyName) )
(export propertyName
(global $global)
(memory $memory)
(func $function)
(table $table)
)
Parameters
configProperty
The name of the property that holds the object exported.
$globalOptional
Points to an existing (global...)
object that contains all the details relating to the object being exported.
$memoryOptional
Points to an existing (memory...)
object that will be exported.
$functionOptional
Points to an existing (func...)
object that to be exported.
$tableOptional
Points to an existing (table...)
object that is being exported.
Examples
(func $add (param $first i32) (param $second i32) (result i32)
local.get $first
local.get $second
i32.add
)
(export "add" $add)
(func (export "add") (param $first i32) (param $second i32) (result i32)
local.get $first
local.get $second
i32.add
)
const wasm = await WebAssembly.instantiateStreaming(fetch('add.wasm'));
const result = wasm.instance.exports.add(42, 101);