Chapter 2. Differences between Gamma and C for GTK

Table of Contents

2.1. Machine-Wrapped Functions
2.2. Lists
2.3. Accessing Widget Resources
2.4. GTK_TYPE_STRUCTURENAME

There are a few differences between the C interface to GTK and the Gamma interface, due to Gamma's underlying functionality.

2.1. Machine-Wrapped Functions

All of the functions and methods in Gamma/GTK have been created by machine wrapping the corresponding C functions, using SWIG (Simplified Wrapper and Interface Generator).

Function/Method Names

Whenever a C function for a specific widget takes the name of the widget as its first argument or only argument, we wrap the function as a method on that widget. For example, the C functions:

void gtk_button_clicked (GtkButton *button);

void gtk_widget_set_usize (GtkWidget *widget,
                           gint width,
                           gint height);

in Gamma become:

GtkButton.clicked();

GtkWidget.set_usize(width, height);

Any C function that doesn't use a widget name as its first argument has the same name in Gamma. For example, the C function:

void gtk_signal_handlers_destroy (GtkObject *object);

in Gamma remains:

gtk_signal_handlers_destroy (object);

Arguments and Return Values

When the functions get wrapped, all the information, including return types, is maintained. However, Gamma's internal Lisp grammar does not allow return value pointers to be passed in as function parameters. Therefore, in the wrapping process we remove all such pointers and keep them in a separate list. Here is how a typical C function would look before wrapping.

int  sample_fn (int a, int* b, float* c, float d)

After wrapping, the return type and any return value(s) are maintained internally in a list, in order from left to right:

(int b c)

The remaining arguments stay with the function, also in order from left to right:

sample_fn(a, d)

The types of a, b, c, and d are checked and maintained internally by Gamma. Depending on the number of return values, there are three possible ways that a Gamma function can return:

    No return value in C returns nil in Gamma.

    One return value in C is the same return value in Gamma.

    Multiple return values passed in as function parameters in C are returned in a list in Gamma, in order from left to right.

All of the above apply whether the C function return type is void or not.

Example

The following output came from the example program ex_wrapping.g:

*** No return values:

The C function gtk_widget_set_uposition() return type is: void
and it has no return value.

The Gamma/GTK method GtkWidget.set_uposition() returns: nil

*** One return value:

The C function gtk_widget_get_name() return type is: gchar

The Gamma/GTK method GtkWidget.get_name() 
applied to the button named 'Exit button' returns: Exit button

*** Multiple return values:

The C function gdk_text_extents() return type is: void
Its return values are: lbearing, rbearing, width, ascent, and descent.
The type of all these return values is: int.

The Gamma/GTK function gdk_text_extents(), when applied to
the string 'Testing' in Courier 12 pt font returns: (0 98 98 9 3)