One more defs user



Hello,

I'm currently writing GTK bindings by hand (to bring GTK into PLT
Scheme) and would rather use the .defs files.  However, they seem to
be missing some information.

For example, gtk_list_store_insert takes a GtkListStore input pointer
and a GtkTreeIter output pointer, but gtk.defs and gtk-types.defs
don't mention that the second pointer is just for output (a return
value).

gtk.defs says:

(define-method insert
  (of-object "GtkListStore")
  (c-name "gtk_list_store_insert")
  (return-type "none")
  (parameters
    '("GtkTreeIter*" "iter")
    '("gint" "position")
  )
)

But in Scheme (using a libffi wrapper), I have to write:

(defgtk gtk_list_store_insert
   (_fun _GtkListStorePtr (iter : (_ptr o _GtkTreeIter)) _int -> _void
-> iter)))

where _fun says gtk_list_store_insert is a function, (_ptr o
_GtkTreeIter) says iter is an output pointer, and "-> _void -> iter"
says the C function returns void but the Scheme function returns iter.

It would be nice if gtk.defs could say:

(define-method insert
  (of-object "GtkListStore")
  (c-name "gtk_list_store_insert")
  (return-type "none")
  (parameters
    '("GtkTreeIter*" "iter" output)
    '("gint" "position")
  )
)


The other part missing right now is computed parameters.  For example,
in gtk_drag_dest_set:

(define-method drag_dest_set
  (of-object "GtkWidget")
  (c-name "gtk_drag_dest_set")
  (return-type "none")
  (parameters
    '("GtkDestDefaults" "flags")
    '("const-GtkTargetEntry*" "targets")
    '("gint" "n_targets")
    '("GdkDragAction" "actions")
  )
)

targets is actually an array and n_targets is its length.  Neither
bits are specified.  Right now I write:

(defgtk gtk_drag_dest_set
  (_fun _GtkWidgetPtr
           _GtkDestDefaults
          (targets : (_list i _GtkTargetEntry))
          (_int = (length targets))
         _GdkDragAction
        -> _void))

and it would be nice if gtk.specs said something like:

(define-method drag_dest_set
  (of-object "GtkWidget")
  (c-name "gtk_drag_dest_set")
  (return-type "none")
  (parameters
    '("GtkDestDefaults" "flags")
    '("const-GtkTargetEntry*" "targets" list)
    '("gint" "n_targets" (auto (length "targets")))
    '("GdkDragAction" "actions")
  )
)

I don't think any of the additions would break existing tools,
considering the first and second elements of the type&name lists stay
the same.


Thanks,
Daniel



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]