Date: Sat, 10 Sep 2005 14:48:38 -0300 From: romildo at uber.com.br To: lablgtk at math.nagoya-u.ac.jp Subject: Wrapping a new widget Message-ID: <20050910174838.GA16269 at malaquias> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MGYHOYXEY6WxJCY8" Content-Disposition: inline --MGYHOYXEY6WxJCY8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi. I want to learn how to wrap a new widget from a C library. For that I am working with the gtk+extra library (http://gtkextra.sourceforge.net/). To start with, I am wrapping just the constructor of the widget GtkPlotCanvas. The programs needed are attached. When compiling the test program with compiler option -i, we can see the infered types of the values: $ ocamlc -i lablgtk.cma gtkInit.cmo gExtra.cmo lablgtkextra.cma test-extra.ml -o test-extra File "test-extra.ml", line 10, characters 2-50: Warning: this expression should have type unit. val window : GWindow.window val canvas : GObj.widget val main : unit -> unit I was expecting the type of canvas to be GExtra.plot_canvas instead of GObj.widget. Please, help me to change this program so that this is the case. Romildo --MGYHOYXEY6WxJCY8 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ml_gtkextra.c" /* ml_gtkextra.c */ #include #include #include #include #include #include #include "wrappers.h" #include "ml_glib.h" #include "ml_gobject.h" #include "ml_gdk.h" #include "ml_gtk.h" #include "gtk_tags.h" CAMLprim value ml_gtkextra_init(value unit) { GType t = gtk_plot_canvas_get_type (); return Val_GType(t); } #define GtkPlotCanvas_val(val) check_cast(GTK_PLOT_CANVAS,val) ML_3 (gtk_plot_canvas_new, Int_val, Int_val, Double_val, Val_GtkWidget_sink) --MGYHOYXEY6WxJCY8 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gtkExtra.ml" (* gtkExtra.ml *) open Gaux open Gobject open Gtk open Tags open GtkBase external _gtkextra_init : unit -> unit = "ml_gtkextra_init" let () = _gtkextra_init () type plot_canvas = [Gtk.widget|`plot_canvas] module PlotCanvas = struct external new_plot_canvas : int -> int -> float -> plot_canvas Gobject.obj = "ml_gtk_plot_canvas_new" end --MGYHOYXEY6WxJCY8 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="gExtra.ml" (* gExtra.ml *) open StdLabels open Gaux open Gobject open Gtk open GtkBase open GtkExtra open GObj class plot_canvas obj = object inherit GObj.widget (obj : GtkExtra.plot_canvas Gtk.obj) end let plot_canvas width heigth magnification ?packing ?show () = let w = PlotCanvas.new_plot_canvas width heigth magnification in GObj.pack_return (new plot_canvas w) ~packing ~show --MGYHOYXEY6WxJCY8--