# WasmModule

Class · category: Framework

Source: https://github.com/playcanvas/engine/blob/970d89f6d3bc6667f4e1f88153abd6e7e82ed52c/src/core/wasm-module.js#L149

A pure static utility class which supports immediate and lazy loading of
[WebAssembly](https://developer.mozilla.org/en-US/docs/WebAssembly) modules. Note that you can
load WebAssembly modules even before instantiating your [AppBase](https://api.playcanvas.com/engine/classes/AppBase.md) instance.

This class is generally only needed if you are developing against the Engine directly. Editor
projects automatically load WebAssembly modules included in the project's assets.

Do not use this class to load the Basis WebAssembly module. Instead, please refer to
[basisInitialize](https://api.playcanvas.com/engine/functions/basisInitialize.md).

**Example**

```ts
// Load the Ammo.js physics engine
WasmModule.setConfig('Ammo', {
    glueUrl: `ammo.wasm.js`,
    wasmUrl: `ammo.wasm.wasm`,
    fallbackUrl: `ammo.js`
});
await new Promise((resolve) => {
    WasmModule.getInstance('Ammo', () => resolve());
});
```

## Methods

### getConfig

```ts
static getConfig(moduleName: string): any
```

Get a wasm module's configuration.

**Parameters**

- `moduleName` (`string`): Name of the module.

**Returns** `any`: The previously set configuration.

### getInstance

```ts
static getInstance(moduleName: string, callback: ModuleInstanceCallback): void
```

Get a wasm module instance. The instance will be created if necessary and returned
in the second parameter to callback.

**Parameters**

- `moduleName` (`string`): Name of the module.
- `callback` ([`ModuleInstanceCallback`](https://api.playcanvas.com/engine/types/ModuleInstanceCallback.md)): The function called when the instance is
  available.

### setConfig

```ts
static setConfig(moduleName: string, config?: object): void
```

Set a wasm module's configuration.

**Parameters**

- `moduleName` (`string`): Name of the module.
- `config` (`object`, optional): The configuration object.
    - `config.errorHandler` ([`ModuleErrorCallback`](https://api.playcanvas.com/engine/types/ModuleErrorCallback.md), optional): Function to be called if the module fails
      to download.
    - `config.fallbackUrl` (`string`, optional): URL of the fallback script to use when wasm modules
      aren't supported.
    - `config.glueUrl` (`string`, optional): URL of glue script.
    - `config.numWorkers` (`number`, optional): For modules running on worker threads, the number of
      threads to use. Default value is based on module implementation.
    - `config.wasmUrl` (`string`, optional): URL of the wasm script.
