[Haskell-cafe] FFI newbie question
John Meacham
john at repetae.net
Fri Mar 14 10:29:25 EDT 2008
On Fri, Mar 14, 2008 at 09:54:11PM +0800, Verma Anurag-VNF673 wrote:
> I am trying to figure out how to pass array of String (char **) from C
> to Haskell? I have read the FFI examples, but most of them are centered
> on calling C from Haskell. I have read in the mailing list, it is rare
> to call Haskell from C, but my requirement is such that I am going to
> write Haskell library that needs to be called from C.
here is a simple example. the first argument is the number of strings,
the second is the pointer. The same code will work whether you are
calling C from haskell or vice versa.
getargs :: Int -> (Ptr CString) -> IO [String]
getArgs argc argv = do
let f n = peekElemOff argv n >>= peekCString
mapM f [0 .. fromIntegral argc - 1]
John
--
John Meacham - ⑆repetae.net⑆john⑈
More information about the Haskell-Cafe
mailing list