bindings-common-0.2.6: Macros and modules to facilitate writing library bindings.Source codeContentsIndex
Bindings.Utilities
Synopsis
data Storable a => GlobalVariable a
writeGlobalVariable :: Storable a => GlobalVariable a -> a -> IO ()
readGlobalVariable :: Storable a => GlobalVariable a -> IO a
class Storable cb => Callback cb where
type F cb :: *
nullCallback :: cb
makeCallback :: F cb -> IO cb
freeCallback :: cb -> IO ()
withCallback :: F cb -> (cb -> IO a) -> IO a
Documentation
data Storable a => GlobalVariable a Source
Haskell FFI imports global variables as pointers. To ease manipulation of such pointers they are encapsulated by GlobalVariable so that values can be reached directly, much like in an Data.IORef.
writeGlobalVariable :: Storable a => GlobalVariable a -> a -> IO ()Source
readGlobalVariable :: Storable a => GlobalVariable a -> IO aSource
class Storable cb => Callback cb whereSource
When libraries provide types for functions those types are made instances of class Callback. That class is used to exchange between Haskell functions and a representation (i.e., a hidden pointer) that can be used or is provided by foreign code.
Associated Types
type F cb :: *Source
The associated type is the function type as it is used in Haskell.
Methods
nullCallback :: cbSource
nullCallback can be used like Foreign.Ptr.nullFunPtr.
makeCallback :: F cb -> IO cbSource
makeCallback takes a Haskell function and gives a representation of it in the form of the type expected by foreign code.
freeCallback :: cb -> IO ()Source
freeCallback should be called on all values returned by makeCallback after they are no longer going to be used. Most of the time this class method will just use Foreign.Ptr.freeHaskellFunPtr.
withCallback :: F cb -> (cb -> IO a) -> IO aSource
withCallback just inserts an action between calls to makeCallback and freeCallback. Of course, it can't be used when foreign code will save such action for latter use.
Produced by Haddock version 2.4.2