bindings-common 0.1 → 0.1.1
raw patch · 2 files changed
+42/−7 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Bindings.Utilities: getGlobalVariable :: (Storable a) => GlobalVariable a -> IO a
- Bindings.Utilities: setGlobalVariable :: (Storable a) => GlobalVariable a -> a -> IO ()
+ Bindings.Utilities: readGlobalVariable :: (Storable a) => GlobalVariable a -> IO a
+ Bindings.Utilities: writeGlobalVariable :: (Storable a) => GlobalVariable a -> a -> IO ()
Files
- bindings-common.cabal +2/−2
- src/Bindings/Utilities.hs +40/−5
bindings-common.cabal view
@@ -2,14 +2,14 @@ name: bindings-common homepage: http://bitbucket.org/mauricio/bindings synopsis:- Common functionality for bindings-* set of packages.+ Low-level library bindings, base package. description: The @bindings-*@ set of packages contain low level bindings for established libraries, and is aimed at developers of higher level modules that can use it as foundation. They all mimic the exact names and functionality of the original libraries. For a specific library, look for package @bindings-library_name@.-version: 0.1+version: 0.1.1 license: BSD3 license-file: LICENSE maintainer: Maurício C. Antunes
src/Bindings/Utilities.hs view
@@ -1,7 +1,7 @@ module Bindings.Utilities ( - GlobalVariable, setGlobalVariable, getGlobalVariable,+ GlobalVariable, writeGlobalVariable, readGlobalVariable, Callback(..) ) where@@ -10,19 +10,54 @@ import Foreign.C import Data.Int +-- | 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".+ newtype (Storable a) => GlobalVariable a = GlobalVariable (Ptr a) -setGlobalVariable :: (Storable a) => GlobalVariable a -> a -> IO ()-setGlobalVariable (GlobalVariable p) v = poke p v+writeGlobalVariable :: (Storable a) => GlobalVariable a -> a -> IO ()+writeGlobalVariable (GlobalVariable p) v = poke p v -getGlobalVariable :: (Storable a) => GlobalVariable a -> IO a-getGlobalVariable (GlobalVariable p) = peek p+readGlobalVariable :: (Storable a) => GlobalVariable a -> IO a+readGlobalVariable (GlobalVariable p) = peek p +-- | 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.+ class (Storable cb) => Callback cb where++ -- | The associated type is the function type+ -- as it is used in Haskell.+ type F cb :: *++ -- | 'nullCallback' can be used like 'Foreign.Ptr.nullPtr'+ -- or 'Foreign.Ptr.nullFunPtr'.+ nullCallback :: cb++ -- | 'makeCallback' takes a Haskell function and+ -- gives a representation of it in the form of the+ -- type expected by foreign code.+ makeCallback :: F cb -> IO cb++ -- | 'freeCallback' should be called on all members+ -- of a foreign function type after they+ -- are no longer going to be used.+ freeCallback :: cb -> IO ()++ -- | 'withCallback' just inserts an action between+ -- calls to 'makeCallback' and 'freeCallback'.+ -- Of course, it can't be used when foreign code+ -- will save the function for latter use.+ withCallback :: F cb -> (cb -> IO a) -> IO a withCallback f c = do made <- makeCallback f