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

WasmEdge.Internal.FFI.Basic

Description

Direct 'foreign import' declarations for all WasmEdge basic C API functions, via the cbits/wasmedge_hs_shims.c shim layer. All struct-by-value returns have been converted to out-pointer style.

Do not import this module in user code.

Synopsis

Version

c_VersionGet :: IO CString #

Get the version string of the WasmEdge C API (e.g., "0.18.0"). The returned pointer points to a static string — do NOT free it.

c_VersionGetMajor :: IO Word32 #

Get the major version number.

c_VersionGetMinor :: IO Word32 #

Get the minor version number.

c_VersionGetPatch :: IO Word32 #

Get the patch version number.

Logging

c_LogSetErrorLevel :: IO () #

Set the logging system to filter to error level only.

c_LogSetDebugLevel :: IO () #

Set the logging system to filter to debug level (verbose).

c_LogOff :: IO () #

Turn off all logging output.

c_LogSetLevel :: Word32 -> IO () #

Set the log level to a specific Word32 value (maps to WasmEdge_LogLevel enum). Use the LogLevel type and logLevelToC for safe access.

c_LogSetCallback :: FunPtr RawLogCallbackT -> IO () #

Set a custom log callback (safe: callback may call back into Haskell).

String (via shims)

c_StringCreateByCString :: Ptr CString_ -> CString -> IO () #

Create a WasmEdge_String from a NULL-terminated C string. Caller owns the result; call c_StringDelete to free.

c_StringCreateByBuffer :: Ptr CString_ -> CString -> Word32 -> IO () #

Create a WasmEdge_String from a buffer with explicit length. Caller owns the result; call c_StringDelete to free.

c_StringWrap :: Ptr CString_ -> CString -> Word32 -> IO () #

Wrap a buffer as a WasmEdge_String (no copy; DO NOT call c_StringDelete).

c_StringIsEqual :: Ptr CString_ -> Ptr CString_ -> IO CBool #

Compare two WasmEdge_String objects for equality.

c_StringCopy :: Ptr CString_ -> CString -> Word32 -> IO Word32 #

Copy the content of a WasmEdge_String into a buffer.

c_StringDelete :: Ptr CString_ -> IO () #

Delete (free) a WasmEdge_String created by 'c_StringCreateBy*'.

c_StringGetLength :: Ptr CString_ -> IO Word32 #

Get the length of a WasmEdge_String.

c_StringGetBuf :: Ptr CString_ -> IO CString #

Get the const char* buffer of a WasmEdge_String.

Bytes (via shims)

c_BytesCreate :: Ptr CBytes_ -> Ptr Word8 -> Word32 -> IO () #

Create a WasmEdge_Bytes from a buffer (copies the data). Caller owns the result; call c_BytesDelete to free.

c_BytesWrap :: Ptr CBytes_ -> Ptr Word8 -> Word32 -> IO () #

Wrap a buffer as WasmEdge_Bytes (no copy; DO NOT call c_BytesDelete).

c_BytesDelete :: Ptr CBytes_ -> IO () #

Delete a WasmEdge_Bytes created by c_BytesCreate.

c_BytesGetLength :: Ptr CBytes_ -> IO Word32 #

Get the length of a WasmEdge_Bytes.

c_BytesGetBuf :: Ptr CBytes_ -> IO (Ptr Word8) #

Get the const uint8_t* buffer of a WasmEdge_Bytes.

Result (via shims)

c_Result_Success :: Ptr CResult_ -> IO () #

Fill a CResult_ with the Success code (0x00).

c_Result_Terminate :: Ptr CResult_ -> IO () #

Fill a CResult_ with the Terminate code (0x01).

c_Result_Fail :: Ptr CResult_ -> IO () #

Fill a CResult_ with the Fail code (0x02).

c_ResultOK :: Ptr CResult_ -> IO CBool #

Check whether a CResult_ represents success (Success or Terminate).

c_ResultGen :: Ptr CResult_ -> Word32 -> Word32 -> IO () #

Generate a result with a specific error category and code. Category is a Word32 mapping to WasmEdge_ErrCategory.

c_ResultGetCode :: Ptr CResult_ -> IO Word32 #

Get the 24-bit error code from a CResult_.

c_ResultGetCategory :: Ptr CResult_ -> IO Word32 #

Get the error category as a Word32.

c_ResultGetMessage :: Ptr CResult_ -> IO CString #

Get the error message as a static C string (do NOT free).

Raw callback type

type RawLogCallbackT = Ptr () -> IO () #

The raw C type of a log callback: void callback(const WasmEdge_LogMessage *msg)

We represent the message pointer as 'Ptr ()' since hsc2hs will resolve the exact struct layout separately. Users should use the public setLogCallback API instead of this raw import.