wasmedge-hs-0.17.1.0: Haskell bindings for the WasmEdge WebAssembly runtime
Copyright(c) 2026 Tushar Adhatrao
LicenseMIT
Stabilitystable
Safe HaskellNone
LanguageGHC2021

WasmEdge.Module

Description

Provides types and functions for managing WebAssembly module instances:

Synopsis

Module instance

newtype ModuleInstance #

A WebAssembly module instance (guest module or host module).

createHostModule :: Text -> IO ModuleInstance #

Create an empty host module instance with the given module name.

createWASIModule :: [Text] -> [Text] -> [Text] -> IO ModuleInstance #

Create a WASI module instance initialized with arguments, environment variables, and preopened directory mappings.

  • args: command-line arguments (e.g., ["prog", "arg1"])
  • envs: environment variables in "KEY=VALUE" format
  • preopens: directory mappings in "guest_dir:host_dir" format

withHostModule :: Text -> (ModuleInstance -> IO a) -> IO a #

Scoped host module instance.

withWASIModule :: [Text] -> [Text] -> [Text] -> (ModuleInstance -> IO a) -> IO a #

Scoped WASI module instance.

WASI functions

initWASI :: ModuleInstance -> [Text] -> [Text] -> [Text] -> IO () #

Re-initialize WASI parameters on an existing WASI module instance.

getWASIExitCode :: ModuleInstance -> IO Word32 #

Get the exit code from WASI execution.

Queries

getModuleName :: ModuleInstance -> IO Text #

Get the exported module name.

findFunction :: ModuleInstance -> Text -> IO (Maybe FunctionInstance) #

Find an exported function by name.

findTable :: ModuleInstance -> Text -> IO (Maybe TableInstance) #

Find an exported table by name.

findMemory :: ModuleInstance -> Text -> IO (Maybe MemoryInstance) #

Find an exported memory by name.

findGlobal :: ModuleInstance -> Text -> IO (Maybe GlobalInstance) #

Find an exported global by name.

findTag :: ModuleInstance -> Text -> IO (Maybe TagInstance) #

Find an exported exception tag by name (0.18+).

listFunctions :: ModuleInstance -> IO [Text] #

List all exported function names.

listTables :: ModuleInstance -> IO [Text] #

List all exported table names.

listMemories :: ModuleInstance -> IO [Text] #

List all exported memory names.

listGlobals :: ModuleInstance -> IO [Text] #

List all exported global names.

listTags :: ModuleInstance -> IO [Text] #

List all exported tag names (0.18+).

Population (building host modules)

addFunction :: ModuleInstance -> Text -> FunctionInstance -> IO () #

Add a FunctionInstance to a host module under the given export name. Moves ownership of the function instance into the module.

addTable :: ModuleInstance -> Text -> TableInstance -> IO () #

Add a TableInstance to a host module under the given export name. Moves ownership of the table instance into the module.

addMemory :: ModuleInstance -> Text -> MemoryInstance -> IO () #

Add a MemoryInstance to a host module under the given export name. Moves ownership of the memory instance into the module.

addGlobal :: ModuleInstance -> Text -> GlobalInstance -> IO () #

Add a GlobalInstance to a host module under the given export name. Moves ownership of the global instance into the module.

Builder pattern

data ModuleBuilder #

A builder for incrementally assembling a host module.

buildHostModule :: Text -> (ModuleBuilder -> IO ()) -> IO ModuleInstance #

Build a host module using the builder pattern.

builderAddHostFunc :: ToHostFunc f => ModuleBuilder -> Text -> f -> IO () #

Add a typed Haskell host function to a host module builder, automatically inferring its WebAssembly signature and handling argument/result conversions.

Internal / borrowed pointers

borrowModule :: Ptr ModuleInstanceTag -> IO ModuleInstance #

Create a borrowed ModuleInstance from a raw pointer (does not finalize).

ownModule :: Ptr ModuleInstanceTag -> IO ModuleInstance #

Create an owned ModuleInstance from a raw pointer (finalizes with c_ModuleInstanceDelete).

disarmModule :: ModuleInstance -> IO () #

Disarm the GC finalizer of an owned ModuleInstance. Used when ownership is transferred to the C runtime or force-deleted by the VM.