| Copyright | (c) 2026 Tushar Adhatrao |
|---|---|
| License | MIT |
| Stability | internal |
| Safe Haskell | None |
| Language | GHC2021 |
WasmEdge.Internal.Utils
Description
Do not import this module in user code.
Synopsis
- withWasmString :: Text -> (Ptr CString_ -> IO a) -> IO a
- fromWasmString :: Ptr CString_ -> IO Text
- peekWasmString :: Ptr CString_ -> IO Text
- withWasmBytes :: ByteString -> (Ptr CBytes_ -> IO a) -> IO a
- checkResult :: Ptr CResult_ -> IO (Either WasmEdgeError ())
- throwOnFail :: Ptr CResult_ -> IO ()
- maybeNullPtr :: Maybe (Ptr t) -> Ptr t
- fromNullablePtr :: Ptr t -> Maybe (Ptr t)
Text / String conversion
withWasmString :: Text -> (Ptr CString_ -> IO a) -> IO a #
Convert a Haskell Text to a WasmEdge_String (on the stack),
call the action, then delete the string.
fromWasmString :: Ptr CString_ -> IO Text #
Alias for peekWasmString — reads a WasmEdge_String and returns Text.
peekWasmString :: Ptr CString_ -> IO Text #
Peek a WasmEdge_String (by pointer) and convert to Haskell Text.
Does NOT free the string.
withWasmBytes :: ByteString -> (Ptr CBytes_ -> IO a) -> IO a #
Wrap a ByteString as a stack-allocated WasmEdge_Bytes (zero copy),
call the action, and return its result.
Checked result conversion
checkResult :: Ptr CResult_ -> IO (Either WasmEdgeError ()) #
Check a WasmEdge_Result pointer and return 'Right ()' on success
or 'Left WasmEdgeError' on failure.
throwOnFail :: Ptr CResult_ -> IO () #
Like checkResult, but throws WasmEdgeError on failure.
Pointer utilities
maybeNullPtr :: Maybe (Ptr t) -> Ptr t #
Convert a 'Maybe (Ptr t)' to a nullable C pointer.