[MLton-devel] RE: calling SML from C in MLton

Mike Thomas miketh@brisbane.paradigmgeo.com
Wed, 30 Apr 2003 11:16:24 +1000


Hi Stephen.

| Hi Mike.  I wanted to let you know that we have added an experimental
| feature to MLton that allows one to call back to SML from C.  To try
| it out, download experimental version 20030419 from
|
| 	http://www.mlton.org/experimental/
|
| Hopefully this will inspire you to get back to your OpenGL port! :-)

Thanks!  I probably won't be able to do anything serious for a few weeks due
to a release here at work and a backlog of open source promises, but I'll
aim to at least try the callback functionality in the next few days and let
you know how I go.  (Right now on my computer I have simultaneous builds of
Geolog (my work), nhc98 and GHC so things are busy here!)

Looking at the downloads I don't see a Cygwin version, and I can't guarantee
how well I'll go building from source - if you have one available please put
it up.

Cheers

Mike Thomas.

|
| The facility is very simple, but you can build complexity on top of
| it.  The relevant structure is
|
| MLton.FFI:
|    sig
|       val handleCallFromC: (unit -> unit) -> unit
|    end
|
| handleCallFromC allows you to register the (single) SML function that
| is called from C.  On the C side, we export a single function that
| allows you to call back to SML:
|
|   	void MLton_callFromC ();
|
| So, after calling "MLton.FFI.handleCallFromC f", then a call from C to
| MLton_callFromC will cause "f ()" to be run.
|
| To call multiple SML functions, you can build C wrappers around
| MLton_callFromC that set some global integer, which you then dispatch
| on from the SML side to call the appropriate function.  You can also
| pass arguments using a simple hand implemented calling convention in
| which you set globals in the C wrapper and fetch them with _ffi from
| the SML code.
|
| Let us know of any questions or problems.  Thanks.
|
|




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel