Blame docs/defsformat.txt

Packit 98cdb6
Packit 98cdb6
The overall syntax is:
Packit 98cdb6
Packit 98cdb6
     (type-of-thing-being-defined  name-used-to-refer-to-this-thing
Packit 98cdb6
       (attribute-name  attribute-value-depending-on-the-attribute)
Packit 98cdb6
       (attribute-name  attribute-value-depending-on-the-attribute)
Packit 98cdb6
       (attribute-name  attribute-value-depending-on-the-attribute))
Packit 98cdb6
Packit 98cdb6
Some definitions can have a c-declaration field that gives the C code
Packit 98cdb6
we parsed to arrive at the definition. The c-declaration is a quoted
Packit 98cdb6
string because it can contain parentheses and such.
Packit 98cdb6
Packit 98cdb6
Defined types and their attributes:
Packit 98cdb6
Packit 98cdb6
===
Packit 98cdb6
(module module-name
Packit 98cdb6
  (submodule-of module-name)) ;; submodule is optional
Packit 98cdb6
Packit 98cdb6
Ex: (module Gtk)
Packit 98cdb6
Ex: (module Rgb
Packit 98cdb6
      (submodule-of Gdk))
Packit 98cdb6
Packit 98cdb6
modules are later referred to with a list of module names, like 
Packit 98cdb6
(Gdk Rgb) or (Gtk)
Packit 98cdb6
Packit 98cdb6
Object and boxed type definitions automatically create a submodule.
Packit 98cdb6
For example, GtkCList creates the module (module CList (submodule-of
Packit 98cdb6
(Gtk))) which is referred to as module (Gtk CList).
Packit 98cdb6
Packit 98cdb6
===
Packit 98cdb6
Packit 98cdb6
(type
Packit 98cdb6
 (alias some-unique-identifier)
Packit 98cdb6
 (in-module module-name)   ;; optional, gchar* is not in a module
Packit 98cdb6
 (gtk-type-id gtk-type-system-id) ;; optional, absent if this is not
Packit 98cdb6
                                  ;; in the type system
Packit 98cdb6
 (is-parametric boolean)          ;; optional default to #f
Packit 98cdb6
 (in-c-name name-of-symbol-in-C)
Packit 98cdb6
 (out-c-name name-of-symbol-in-C)
Packit 98cdb6
 (inout-c-name name-of-symbol-in-C))
Packit 98cdb6
Packit 98cdb6
Ex: (type
Packit 98cdb6
     (alias string)
Packit 98cdb6
     (gtk-type-id GTK_TYPE_STRING)
Packit 98cdb6
     (in-c-name "const gchar*")
Packit 98cdb6
     (out-c-name "gchar**")      ;; actually I'm not sure how strings work out/inout
Packit 98cdb6
     (inout-c-name "gchar*"))
Packit 98cdb6
Packit 98cdb6
 (type
Packit 98cdb6
     (alias list)
Packit 98cdb6
     (gtk-type-id GTK_TYPE_POINTER)
Packit 98cdb6
     (is-parametric #t)
Packit 98cdb6
     (in-c-name "GList*")
Packit 98cdb6
     (out-c-name "GList**")
Packit 98cdb6
     (inout-c-name "GList**"))
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
 ;; This one would be implied by the (object) def for GtkWidget I
Packit 98cdb6
 ;; think - (type) is only required for types that are not implied
Packit 98cdb6
 ;; by other definitions, such as int/boolean/etc.
Packit 98cdb6
 
Packit 98cdb6
    (type
Packit 98cdb6
     (alias GtkWidget)
Packit 98cdb6
     (in-module (Gtk))
Packit 98cdb6
     (gtk-type-id GTK_TYPE_WIDGET)
Packit 98cdb6
     (in-c-name "GtkWidget*")
Packit 98cdb6
     (inout-c-name "GtkWidget*")
Packit 98cdb6
     (out-c-name "GtkWidget**"))
Packit 98cdb6
Packit 98cdb6
"Type" bindings are automatically assumed for objects, boxed types,
Packit 98cdb6
etc. as defined below.
Packit 98cdb6
Packit 98cdb6
The alias field is used to refer to the type later on.
Packit 98cdb6
Packit 98cdb6
Whenever a type alias can be used, it is also possible to use the
Packit 98cdb6
keyword "native", which implies that the type in question is too
Packit 98cdb6
C-specific to represent. Then a c-declaration will typically be
Packit 98cdb6
available for use.
Packit 98cdb6
Packit 98cdb6
C types containing [] or () are function pointers or arrays. For
Packit 98cdb6
arrays that don't specify a size, we just treat them as pointers. For
Packit 98cdb6
function pointers, we need special (type) syntax/attributes of some
Packit 98cdb6
kind, but since there basically aren't any of these right now in the
Packit 98cdb6
libs we care about we can just ignore them. For arrays that specify a
Packit 98cdb6
size ditto, you would handle them by adding an (array-size) attribute
Packit 98cdb6
or something or using the "native" keyword and skipping the (type)
Packit 98cdb6
stuff.
Packit 98cdb6
Packit 98cdb6
===
Packit 98cdb6
(object object-name
Packit 98cdb6
   (in-module module-name-list)
Packit 98cdb6
   (parent object-name optional-module-name-if-different)
Packit 98cdb6
   (abstract boolean-is-abstract-class) ;; omit for default of #f
Packit 98cdb6
   (c-name name-of-the-object-in-C)
Packit 98cdb6
   (field (type-and-name type-alias-of-struct-field name-of-struct-field)
Packit 98cdb6
          (access read-or-write-or-readwrite)))
Packit 98cdb6
   
Packit 98cdb6
Packit 98cdb6
Ex: (object Widget
Packit 98cdb6
      (in-module (Gtk))
Packit 98cdb6
      (parent Object)      ;; could say (parent Object (Gtk))
Packit 98cdb6
      (abstract #t)
Packit 98cdb6
      (c-name GtkWidget)
Packit 98cdb6
      (field (type-and-name GdkWindow* window) (access read)))
Packit 98cdb6
Packit 98cdb6
An "object" declaration automatically implies the type definition:
Packit 98cdb6
Packit 98cdb6
(type
Packit 98cdb6
  (alias concat-module-elements-and-object-name)
Packit 98cdb6
  (in-c-name pointer-to-c-name)
Packit 98cdb6
  (out-c-name pointer-to-pointer-to-c-name)
Packit 98cdb6
  (inout-c-name pointer-to-c-name))
Packit 98cdb6
Packit 98cdb6
Ex: 
Packit 98cdb6
 (type (alias GtkWidget) 
Packit 98cdb6
       (in-c-name GtkWidget*) 
Packit 98cdb6
       (out-c-name GtkWidget**) 
Packit 98cdb6
       (inout-c-name GtkWidget*))
Packit 98cdb6
Packit 98cdb6
It also implies a module that is the name broken into parts:
Packit 98cdb6
 (module CTree
Packit 98cdb6
   (submodule-of Gtk))
Packit 98cdb6
Packit 98cdb6
===
Packit 98cdb6
Packit 98cdb6
(function function-name
Packit 98cdb6
  (in-module module-name-list) ;; "static methods" go in their
Packit 98cdb6
                               ;;  object's module
Packit 98cdb6
  (is-constructor-of object-type-alias) ;; optional, marks a constructor
Packit 98cdb6
  (c-name function-name)
Packit 98cdb6
  (return-type return-value-type) ;; defaults to void
Packit 98cdb6
  (caller-owns-return boolean-value) ;; defaults to #f
Packit 98cdb6
  (can-return-null boolean-value) ;; defaults to #t
Packit 98cdb6
  (parameter in-or-out-or-inout 
Packit 98cdb6
      (type-and-name parameter-type-alias parameter-name)
Packit 98cdb6
      (type-parameter name-of-contained-type) ;; optional, requires parametric type
Packit 98cdb6
      (c-declaration "c-type-and-name")) ;; c-declaration only required
Packit 98cdb6
                                         ;; if the type alias is "native"
Packit 98cdb6
  (varargs #t) ;; has varargs at the end
Packit 98cdb6
)
Packit 98cdb6
Packit 98cdb6
Ex:
Packit 98cdb6
  (function init
Packit 98cdb6
    (in-module (Gdk Rgb)
Packit 98cdb6
    (c-name gdk_rgb_init)))
Packit 98cdb6
Packit 98cdb6
Ex: 
Packit 98cdb6
  (function new
Packit 98cdb6
    (in-module (Gdk Rgb Cmap))
Packit 98cdb6
    (is-constructor-of GdkRgbCmap)
Packit 98cdb6
    (c-name gdk_rgb_cmap_new)
Packit 98cdb6
    (return-type GdkRgbCmap)
Packit 98cdb6
    (caller-owns-return #t)   ;; perhaps this could be implied by is-constructor-of
Packit 98cdb6
    (parameter in (type-and-name array-of-guint32 colors))
Packit 98cdb6
    (parameter in (type-and-name gint n_colors)))
Packit 98cdb6
Packit 98cdb6
Ex:
Packit 98cdb6
  (function config_set_set_handler
Packit 98cdb6
   (in-module (Gnome))
Packit 98cdb6
   (c-name gnome_config_set_set_handler)
Packit 98cdb6
   (parameter in (type-and-name native func)
Packit 98cdb6
                 (c-declaration "void (*func)(void*)"))
Packit 98cdb6
   (parameter in (type-and-name gpointer data)))  
Packit 98cdb6
Packit 98cdb6
===
Packit 98cdb6
(method method-name
Packit 98cdb6
  (of-object object-name module-name)
Packit 98cdb6
  ;; retval/arg attributes as for (function), but with first parameter
Packit 98cdb6
  ;; omitted for non-constructors
Packit 98cdb6
   )
Packit 98cdb6
 
Packit 98cdb6
Ex:
Packit 98cdb6
  (method set_text
Packit 98cdb6
     (of-object Label (Gtk))
Packit 98cdb6
     (parameter (type-and-name const-gchar* str)))
Packit 98cdb6
Packit 98cdb6
===
Packit 98cdb6
(object-argument arg-name
Packit 98cdb6
   (of-object object-we-are-an-argument-of optional-objects-module)
Packit 98cdb6
   (type-id argument-type)       ;; GTK_TYPE_OBJECT etc.
Packit 98cdb6
   ;; flags all default to #f
Packit 98cdb6
   (readable bool-value)
Packit 98cdb6
   (writeable bool-value)
Packit 98cdb6
   (construct-only bool-value))
Packit 98cdb6
Packit 98cdb6
Ex:
Packit 98cdb6
  (object-argument label
Packit 98cdb6
     (of-object Label (Gtk))
Packit 98cdb6
     (type GTK_TYPE_STRING)
Packit 98cdb6
     (readable #t)
Packit 98cdb6
     (writeable #t))
Packit 98cdb6
Packit 98cdb6
=== 
Packit 98cdb6
(signal signal-name
Packit 98cdb6
  (run-action bool-value)
Packit 98cdb6
  (run-first bool-value)
Packit 98cdb6
  (run-last bool-value)
Packit 98cdb6
  (of-object object-we-are-a-signal-of optional-objects-module)
Packit 98cdb6
  ;; return value and parameters as for a function, omitting the object
Packit 98cdb6
  ;; and user data parameters
Packit 98cdb6
Packit 98cdb6
  ;; what other properties matter for a signal?
Packit 98cdb6
)
Packit 98cdb6
Packit 98cdb6
Ex:
Packit 98cdb6
  (signal select_row
Packit 98cdb6
     (of-object CList (Gtk))
Packit 98cdb6
     (run-first #t)
Packit 98cdb6
     ;; return type defaults to void
Packit 98cdb6
     (parameter in (type-and-name gint row))
Packit 98cdb6
     (parameter in (type-and-name gint column))
Packit 98cdb6
     (parameter in (type-and-name GdkEvent* event)))
Packit 98cdb6
Packit 98cdb6
=== 
Packit 98cdb6
(enum enum-name
Packit 98cdb6
  (in-module modname)
Packit 98cdb6
  (c-name name-in-c)
Packit 98cdb6
  (value (nick value-name-noprefixes-hyphen-lowercase) (c-name value-c-name)))
Packit 98cdb6
Packit 98cdb6
Ex:
Packit 98cdb6
Packit 98cdb6
  (enum DirectionType
Packit 98cdb6
    (in-module Gtk)
Packit 98cdb6
    (c-name GtkDirectionType)
Packit 98cdb6
    (value (nick tab-forward) (c-name GTK_DIR_TAB_FORWARD))
Packit 98cdb6
    (value (nick tab-backward) (c-name GTK_DIR_TAB_BACKWARD))
Packit 98cdb6
    (value (nick up) (c-name GTK_DIR_UP))
Packit 98cdb6
    (value (nick down) (c-name GTK_DIR_DOWN))
Packit 98cdb6
    (value (nick left) (c-name GTK_DIR_LEFT))
Packit 98cdb6
    (value (nick right) (c-name GTK_DIR_RIGHT)))
Packit 98cdb6
Packit 98cdb6
  (enum Pos
Packit 98cdb6
    (in-module (Gtk CTree))
Packit 98cdb6
    (c-name GtkCTreePos)
Packit 98cdb6
    (value (nick before) (c-name GTK_CTREE_POS_BEFORE))
Packit 98cdb6
    (value (nick as-child) (c-name GTK_CTREE_POS_AS_CHILD))
Packit 98cdb6
    (value (nick after) (c-name GTK_CTREE_POS_AFTER)))
Packit 98cdb6
Packit 98cdb6
===
Packit 98cdb6
(flags) is just like enum, but some bindings may wrap enums and flags differently.
Packit 98cdb6
    
Packit 98cdb6
===
Packit 98cdb6
Packit 98cdb6
(boxed boxed-name
Packit 98cdb6
  (in-module modname)
Packit 98cdb6
  (c-name c-name)
Packit 98cdb6
  (ref-func func-to-increase-refcount)
Packit 98cdb6
  (copy-func func-to-copy)
Packit 98cdb6
  (release-func func-to-destroy-or-decrement-refcount)
Packit 98cdb6
  (field (type-and-name type-alias-of-struct-field name-of-struct-field) (access access-rule)))
Packit 98cdb6
Packit 98cdb6
It is never OK to use memcpy() to copy a boxed type, or use
Packit 98cdb6
malloc()/free() to alloc/free one.
Packit 98cdb6
Packit 98cdb6
Ex:
Packit 98cdb6
Packit 98cdb6
 (boxed Pixmap
Packit 98cdb6
   (in-module (Gdk))
Packit 98cdb6
   (c-name GdkPixmap)
Packit 98cdb6
   (ref-func pixmap_ref)
Packit 98cdb6
   (release-func pixmap_unref))
Packit 98cdb6
Packit 98cdb6
An "object" declaration automatically implies the type definition:
Packit 98cdb6
Packit 98cdb6
(type
Packit 98cdb6
  (alias concat-module-elements-and-boxed-name)
Packit 98cdb6
  (in-c-name pointer-to-c-name)
Packit 98cdb6
  (out-c-name pointer-to-pointer-to-c-name)
Packit 98cdb6
  (inout-c-name pointer-to-c-name))
Packit 98cdb6
Packit 98cdb6
Ex: 
Packit 98cdb6
 (type (alias GdkPixmap) 
Packit 98cdb6
       (in-c-name GdkPixmap*) 
Packit 98cdb6
       (out-c-name GdkPixmap**) 
Packit 98cdb6
       (inout-c-name GdkPixmap*))
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
===
Packit 98cdb6
Packit 98cdb6
(struct struct-name
Packit 98cdb6
  (in-module modname)
Packit 98cdb6
  (c-name c-name)
Packit 98cdb6
  (field (type-and-name type-alias-of-struct-field name-of-struct-field) (access access-rule)))
Packit 98cdb6
Packit 98cdb6
Unlike a boxed type, a struct type can be copied with memcpy() and
Packit 98cdb6
allocated on the stack or with g_malloc().
Packit 98cdb6
Packit 98cdb6
Ex:
Packit 98cdb6
 (struct Rectangle
Packit 98cdb6
   (in-module (Gdk))
Packit 98cdb6
   (c-name GdkRectangle)
Packit 98cdb6
   (field (type-and-name gint16 x) (access readwrite))
Packit 98cdb6
   (field (type-and-name gint16 y) (access readwrite))
Packit 98cdb6
   (field (type-and-name guint16 width) (access readwrite))
Packit 98cdb6
   (field (type-and-name guint16 height) (access readwrite)))
Packit 98cdb6
Packit 98cdb6
Implies GdkRectangle type alias:
Packit 98cdb6
Packit 98cdb6
 (type (alias GdkRectangle) 
Packit 98cdb6
       (in-c-name GdkRectangle*) 
Packit 98cdb6
       (out-c-name GdkRectangle*)    ;; note - not the same as boxed types 
Packit 98cdb6
       (inout-c-name GdkRectangle*))
Packit 98cdb6
Packit 98cdb6
===
Packit 98cdb6
Packit 98cdb6
(user-function name
Packit 98cdb6
  (in-module module)
Packit 98cdb6
  (c-name c-typedef-name)
Packit 98cdb6
  ;; return-type and parameters as for (function)
Packit 98cdb6
)
Packit 98cdb6
Packit 98cdb6
Ex:
Packit 98cdb6
Packit 98cdb6
 (user-function PrintFunc
Packit 98cdb6
    (in-module (Gtk))
Packit 98cdb6
    (parameter in (type-and-name gpointer func_data))
Packit 98cdb6
    (parameter in (type-and-name gchar* str)))
Packit 98cdb6
Packit 98cdb6
===
Packit 98cdb6
Packit 98cdb6
(typedef new-name
Packit 98cdb6
  (in-module module)
Packit 98cdb6
  (c-name c-full-name)
Packit 98cdb6
  (orig-type alias-of-orig-type))
Packit 98cdb6
Packit 98cdb6
Ex:
Packit 98cdb6
Packit 98cdb6
 (typedef Type
Packit 98cdb6
   (in-module (Gtk))
Packit 98cdb6
   (c-name GtkType)
Packit 98cdb6
   (orig-type guint))
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
  
Packit 98cdb6
   
Packit 98cdb6