RE: More C interfacing issues
-----Original Message----- From: Alastair Reid [mailto:reid@reid-consulting-uk.ltd.uk] Sent: 02 July 2002 18:34 To: Ian Lynagh Cc: ffi@haskell.org Subject: Re: More C interfacing issues
Firstly, some ncurses calls return a *WINDOW and others take one as an argument but you never actually look at the contents of one yourself. I have defined "data Window = Window" and am using Ptr Window for the types of these. However, this means I get a warning about an unused constructor. Is there a better way to do this?
Hugs supports:
data Window
and I believe GHC and NHC do too. (Malcolm, SimonM: please shout if I overstate.)
Yes, GHC does.
Secondly, does anyone have any suggestions on how to provide an interface to this?
void getyx(WINDOW *win, int y, int x);
The getyx macro places the current cursor position of the given window in the two integer variables y and x.
The type would probably ideally be "Ptr Window -> IO (CInt, CInt)".
The easy way is to use GreenCard (the other ffi frontends may be of use too).
Or, you can do what GreenCard does which is to add 3 wrapper functions more or less like this:
What's wrong with just doing this in the plain FFI? data Window foreign import ccall "getyx" getyx :: Ptr Window -> Ptr CInt -> Ptr CInt -> IO () niceGetYX :: Ptr Window -> IO (CInt, CInt) niceGetYX win = alloca $ \py -> alloca $ \px -> do getyx win py px y <- peek py x <- peek px return (x,y) Have I missed something? Cheers, Simon
Secondly, does anyone have any suggestions on how to provide an interface to this?
void getyx(WINDOW *win, int y, int x);
What's wrong with just doing this in the plain FFI?
foreign import ccall "getyx" getyx :: Ptr Window -> Ptr CInt -> Ptr CInt -> IO ()
Have I missed something?
You need at least one wrapper because getyx is a macro. Note that the arguments are ints _not_ int*s. -- Alastair Reid alastair@reid-consulting-uk.ltd.uk http://www.reid-consulting-uk.ltd.uk/alastair/
participants (2)
-
Alastair Reid -
Simon Marlow