2 Aug 2012 18:08
[ANNOUNCE] dynamic-linker-template: automatically derive dynamic linking methods from a data type.
Sylvain HENRY <hsyl20 <at> gmail.com>
2012-08-02 16:08:15 GMT
2012-08-02 16:08:15 GMT
Hi,
A few days ago I uploaded on Hackage the first release of
dynamic-linker-template package (System.Posix.DynamicLinker.Template).
Basically, it uses Template Haskell to generate boilerplate code to
dynamically load symbols of a shared library into a data defined using
"record" syntax.
Simple example:
----------------------
{-# LANGUAGE TemplateHaskell, ForeignFunctionInterface #-}
import System.Posix.DynamicLinker.Template
data MyLib = MyLib {
-- Mandatory field (name and type)
libHandle :: DL,
-- Mandatory symbol. Will throw an exception if not available
myFunction1 :: Int -> Float,
-- Optional symbol
myFunction2 :: Maybe (Int -> Int)
}
$(makeDynamicLinker ''MyLib CCall 'id)
-- Use any String->String function instead of "id" to transform field
names into symbol names
(Continue reading)
RSS Feed