Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] WxWidgets?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-09-17 (04:40)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] WxWidgets?
On Fri, 2004-09-17 at 10:06, SooHyoung Oh wrote:
> I've followed wxHaskell method and implemented some of widgets
> with Ocaml.
> Implementing all of widgets of wxEiffel C wrapper requires much time,
> so I'm finding more systematic method.
> Can you give me more hints about your comments about
> how to generate Ocaml binding using wxDirect?

The program 'flxcc' contained in my Felix package
contains a wrapper generator which generates Felix
bindings from C header files. Perhaps it can be
modified to create Ocaml bindings.

Flxcc uses the Frontc/Cil parser to parse C header
files, and tries to generate a set of wrappers for
each file (including any #include files encountered).
It handles namespaces, overloading, and classes
but not class constructors (can't figure how to mod
the parser to get that right), and cheats on variadic
functions. It detects most sane callbacks automatically.

The process generates bindings for hundreds of files
in the /usr/include tree on my box including the 
C standard library, Python, and GTK. I have no idea
if they all work though :)

Flxcc treats enountered types as abstract, so you will
still need to provide typemapping functions.

An excerpt from the binding generated for gtkstatusbar
is given below. It should be fairly easy to modify
the output to produce Ocaml mli and C glue. An alternative
would be to generate IDL files and run them through

module gtk_2_0_gtk_gtkstatusbar_h
  open C_hack;
  open glib_2_0_glib_gmem_h;
  open glib_2_0_glib_gslist_h;
  open glib_2_0_glib_gtypes_h;
  open glib_2_0_gobject_gtype_h;
  open gtk_2_0_gdk_gdktypes_h;
  open gtk_2_0_gtk_gtkhbox_h;
  open gtk_2_0_gtk_gtkstyle_h;
  type _struct__GtkStatusbar = 'struct _GtkStatusbar';
  type _struct__GtkStatusbarClass = 'struct _GtkStatusbarClass';
  header '''typedef void
(*gtk_2_0_gtk_gtkstatusbar_h_cft_1)(GtkStatusbar *,  guint,  gchar const
  type gtk_2_0_gtk_gtkstatusbar_h_cft_1 =
  header '''typedef void (*gtk_2_0_gtk_gtkstatusbar_h_cft_2)(void);''';
  type gtk_2_0_gtk_gtkstatusbar_h_cft_2 =
  typedef GtkStatusbarClass = _struct__GtkStatusbarClass;
  typedef GtkStatusbar = _struct__GtkStatusbar;
  proc gtk_statusbar_pop: ptr[GtkStatusbar] * guint =
  proc gtk_statusbar_remove: ptr[GtkStatusbar] * guint * guint =
  proc gtk_statusbar_set_has_resize_grip: ptr[GtkStatusbar] * gboolean =
  fun gtk_statusbar_get_context_id: ptr[GtkStatusbar] * cptr[gchar] ->
guint = 'gtk_statusbar_get_context_id($a)';
  fun gtk_statusbar_get_has_resize_grip: ptr[GtkStatusbar] -> gboolean =
  fun gtk_statusbar_get_type: 1 -> GType = 'gtk_statusbar_get_type($a)';
  fun gtk_statusbar_new: 1 -> ptr[GtkWidget] = 'gtk_statusbar_new($a)';
  fun gtk_statusbar_push: ptr[GtkStatusbar] * guint * cptr[gchar] ->
guint = 'gtk_statusbar_push($a)';


John Skaller,
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: