[MLton] FFI: C void *

Mike Thomas mike.thomas@brisbane.paradigmgeo.com
Wed, 14 Jan 2004 13:39:32 +1000


Hi there.

In the GLUT C header there are a series of font identifiers and character
output functions like this one:

========================================================================
#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
   /* Stroke font constants (use these in GLUT program). */
#  define GLUT_STROKE_ROMAN		((void*)0)
#else
   GLUTAPI void *glutStrokeRoman;
#define GLUT_STROKE_ROMAN		(&glutStrokeRoman)
#endif

.....

   GLUTAPI void APIENTRY glutStrokeCharacter(void *font, int character);
========================================================================

I have tried both a Pointer type:

========================================================================
C Side:
Pointer mlton_glut_stroke_roman(void)
{
  return ((Pointer) GLUT_STROKE_ROMAN);
}

SML side:
  type glutfont = Word32.word array
  val GLUT_STROKE_ROMAN = _import "mlton_glut_stroke_roman" : glutfont;
  val c_glutStrokeCharacter =
       _import  "glutStrokeCharacter" stdcall: glutfont * int -> unit;
  fun glutStrokeCharacter (a:glutfont) (b:int) =
       c_glutStrokeCharacter (a,b)
========================================================================

and a Word32.word type:

========================================================================
C Side:
Word32 mlton_glut_stroke_roman(void)
{
  return ((Word32) GLUT_STROKE_ROMAN);
}

SML Side:
  type glutfont = Word32.word
  val GLUT_STROKE_ROMAN = _import "mlton_glut_stroke_roman" : glutfont;
  val c_glutStrokeCharacter =
       _import  "glutStrokeCharacter" stdcall: glutfont * int -> unit;
  fun glutStrokeCharacter (a:glutfont) (b:int) =
       c_glutStrokeCharacter
(a,b)=======================================================================
=

but still the font example does not work.

  glutBitmapCharacter GLUT_BITMAP_HELVETICA_10 65

It may be that I have done something else wrong but never-the-less I would
appreciate some feedback on whether I have handled this aspect of the
problem (that is, the void *) correctly with either of these two approaches.

(Yes, I'm sending the ord of a character to the glutStrokeCharacter()
function and I intend to change the definition to get the ord from a char
automatically.)

Cheers

Mike Thomas.