[Haskell-cafe] carry "state" around ....
John Meacham
john at repetae.net
Sun Jul 20 02:26:28 EDT 2008
In order to write portable code that accesses C structures, you need to
write a c shim, or better, use the 'hsc2hs' tool to produce portable
code. For an example, you can see my OpenSSL binding code in
http://repetae.net/repos/ginsu/RSA.hsc
in particular the 'createPkey' function. the #ptr construct gets a
pointer to a member of a C structure, and #peek and #poke let you read
and set members. You should use (#const sizeof(struct foo)) to determine
how much memory you need to allocate for a structure. (unless the API
you are binding specifies some other allocation method)
John
--
John Meacham - ⑆repetae.net⑆john⑈
More information about the Haskell-Cafe
mailing list