Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: =?ISO-8859-1?Q?Maur=ED=ADcio_CA?= <mauricio.antunes <at> gmail.com>
Subject: ANN: bindings-DSL 1.0.4 (Category: FFI)
Newsgroups: gmane.comp.lang.haskell.cafe
Date: Saturday 23rd January 2010 03:02:07 UTC (over 6 years ago)
Hi,

bindings-DSL is a mature and well documented preprocessor domain
specific language you can use to generate bindings to a C API.
It's based on functionality provided by hsc2hs. These are links to
Hackage page and documentation:

   http://hackage.haskell.org/package/bindings-DSL
   http://bitbucket.org/mauricio/bindings-dsl

New in this version:

   * Support for C unions.
   * Use of  macros for wider portability.

An example on the use of unions follow. Suppose you have:

   union example {
     int k;
     char c[4];
   };

Then, using bindings-DSL, you'll write:

   #starttype union example
   #union_field k , CInt
   #union_array_field c , CChar
   #stoptype

Here is a ghci session showing the resulting code:

 > let value = C'example 1 []

 > u'example'k value (2^10)

     C'example {c'example'k = 1024, c'example'c = [0,4,0,0]}

 >  u'example'c value [1,0,0,0]

     C'example {c'example'k = 1, c'example'c = [1,0,0,0]}

 > u'example'c value [0,0,0,1]

     C'example {c'example'k = 16777216, c'example'c = [0,0,0,1]}

Peeking an uninitialized memory address:

 > v <- alloca $ \p -> peek p :: IO C'example
 > v

     C'example {c'example'k = 81842189, c'example'c = [13,-48,-32,4]}



Hope it's useful to you. Best,
MaurĂ­cio
 
CD: 3ms