[MLton-devel] calling SML from C in MLton

Stephen Weeks MLton@mlton.org
Tue, 29 Apr 2003 18:00:07 -0700


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! :-)

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