From HaskellWiki
< Library
Revision as of 15:12, 5 March 2011 by Remi (talk | contribs) (add some initial docs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

cinvoke is a library allowing C functions of types only known at runtime to be called from Haskell.

As an example is worth a thousand words:

 module Main where
 import Foreign.Ptr
 import Foreign.CInvoke
 main = do
     cxt <- newContext
     libc <- loadLibrary cxt ""
     malloc <- loadSymbol libc "malloc"
     memset <- loadSymbol libc "memset"
     free   <- loadSymbol libc "free"
     let sz = 2^30
     p <- cinvoke malloc (retPtr retVoid) [argCSize sz]
     cinvoke memset (retPtr retVoid) [argPtr p, argCInt 0, argCSize sz]
     cinvoke free (retPtr retVoid) [argPtr p]