-
Notifications
You must be signed in to change notification settings - Fork 12
Class Documentation: Wasm
Inherits: RefCounted
Compile, instantiate, and interact with a WebAssembly module.
The Wasm
class is the top-level entity you'll deal with when interacting with a WebAssembly module from GDScript. Each Wasm
instance contains at most one instantiated Wasm module.
At a high-level, the following steps must be completed to run a Wasm module.
- Compile the bytecode (via
Wasm.compile()
) - Instantiate the module (via
Wasm.instantiate()
)
A convenience method, Wasm.load()
, is provided to combine the above steps into a single method call.
The Wasm
class holds a reference to an instantiated Wasm modules memory accessible via the WasmMemory class.
Type | Property |
---|---|
Dictionary | permissions |
WasmMemory | memory |
Return | Method |
---|---|
Error | compile ( PackedByteArray bytecode ) |
Error | instantiate ( Dictionary imports ) |
Error | load ( PackedByteArray bytecode, Dictionary imports ) |
Dictionary | inspect () |
Variant | global ( String name ) |
Variant | function ( String name, Array args ) |
bool | has_permission ( String permission ) |
Dictionary permissions
- void permissions ( Dictionary update )
- Dictionary get_permissions ()
WASI permissions for the Wasm
instance.
WasmMemory memory
- WasmMemory get_memory ()
A StreamPeer-like interface for interacting with the memory of an instantiated Wasm module.
Error compile ( PackedByteArray bytecode )
Compile the Wasm module provided Wasm binary bytecode
.
This must be called before instantiating the module. Alternatively, the module can be compiled and instantiated in a single step with load.
Error instantiate ( Dictionary imports )
Instantiate a compiled Wasm module.
Before this can be called, the module must be compiled via compile.
Imported functions can be provided in [code]import_map[/code] in the form var imports = { "functions": { "index.function": [self, "function"] } }
.
Each key of the import_map.functions
should be an array whose members are the object containing the imported method and a string specifying the name of the method.
Alternatively, the module can be compiled and instantiated in a single step with load.
Error load ( PackedByteArray bytecode, Dictionary imports )
Compile and instantiate a Wasm module in a single step. Equivalent to calling compile and instantiate.
Dictionary inspect ()
Inspect the imports, exports, and memories of a compiled Wasm module. Note that this may be called after compiling but before instantiating a module and may even inform the imports provided instantiate.
Access an exported global of the instantiated Wasm module. Returns either a single float or integer.
Call an exported function of the instantiated Wasm module.
The args
argument array must be provided even if no arguments are required.
Returns either a single float or integer.
Checks if the Wasm
instance has permission for the permission
argument.