Box2D
Safe HaskellNone
LanguageGHC2021

Box2D.Internal

Description

Marshalling helpers shared by the binding modules.

By-value calls involving float structs or defs go through the shim as pointers (ids pass directly as words), so the same two idioms recur: read a struct back from an out parameter, and decode a C boolean returned for a marshalled argument.

Synopsis

Documentation

allocaOut :: Storable a => (Ptr a -> IO ()) -> IO a Source #

Run a shim call that writes its result to an out parameter and read it.

withValid :: Storable a => (Ptr a -> IO CBool) -> a -> IO Bool Source #

Marshal a value in and decode the returned C boolean.

copyVector :: Storable a => Int -> Ptr a -> IO (Vector a) Source #

Copy a C-owned array into a Haskell-owned storable vector: one memcpy, no per-element marshalling. Safe to keep after the source is invalidated.

unsafeViewVector :: Int -> Ptr a -> IO (Vector a) Source #

View a C-owned array as a storable vector without copying. The vector aliases engine memory and carries no finalizer: it is only valid while the source buffer is (for event buffers, until the next world step). Prefer copyVector unless the copy shows up in a profile.