From: David M. <Dav...@pr...> - 2001-09-17 20:30:23
|
On Sunday, September 16, 2001 3:19 PM, Dave Berry [SMTP:da...@ta...] wrote: > At 16:03 14/09/2001, Stephen Weeks wrote: > If you have a standard interface to C and a standard for compilation > management, then it becomes much easier to write libraries. Any SML > programmer will be able to write libraries that run on any SML compiler. > That seems a "base level" that everyone on this list should aim for. > > I suggest an IDL interface for the C FLI. People should not have to write > any C themselves. I know SML/NJ were working on this, as were the MLWorks > team. Dave, Have you looked at the foreign function interface that Nick Chapman did for Poly/ML several year ago? (See http://www.lfcs.ed.ac.uk/software/polyml/docs/CInterface.html ). It's been used for several projects but particularly the Windows interface which has several hundred functions in it. It works for dynamic libraries in Unix or DLLs in Windows and doesn't require the SML programmer to write anything but ML. As an example, the following code creates a function to put up a message box using the Windows MessageBox function. MessageBoxA is a function within the user32 DLL and is normally called from C or Visual Basic code but it's just as easy to give it an ML type and call it with ML arguments. local open CInterface fun userDLL name = load_sym (load_lib "user32.dll") name in val MB_OKCANCEL = 0x00000001 val MessageBox = call4 (userDLL "MessageBoxA") (INT, STRING, STRING, INT) INT end; MessageBox is now a function with type int * string * string * int -> int and can be called as MessageBox(0, "Is this OK?", "The title", MB_OKCANCEL); The converters INT and STRING are defined in the library but it's easy to define new converters for arbitrary types. David. |