A.35. Wrapping Functions

#!/usr/cogent/bin/gamma

/* Example: This example demonstrates how the return values are treated
   by machine-wrapped Gamma functions.
   - C functions with 'void' return values return 'nil' in Gamma.
   - C functions with one return value return that value in Gamma.
   - C functions with multiple return values return a list of those
       values in Gamma.
 */

init_ipc("a", "aq");

TRUE = 1;
FALSE = 0;

window = new(GtkWindow);
window.set_border_width(20);
window.title = "";

/* Use a method that has no return value, and print the results. */
ret1 = window.set_uposition(400, 200);
princ(string("\n*** No return values:",
	     "\n\nThe C function gtk_widget_set_uposition() return type is: void",
	     "\nand it has no return value.",
	     "\n\nThe Gamma/GTK method GtkWidget.set_uposition() returns: ", ret1, "\n"));

/* Create a button. */
button = new(GtkButton);
button.label = " Exit ";
button.name = "Exit button";

/* Use a method that has one return value, and print the results. */
ret2 = button.get_name();
princ(string("\n*** One return value:",
	     "\n\nThe C function gtk_widget_get_name() return type is: gchar",
	     "\n\nThe Gamma/GTK method GtkWidget.get_name() ",
	     "\napplied to the button named 'Exit button' returns: ", ret2, "\n"));

/* Create a font, a string, and a text box to display them. */
font = gdk_font_load ("-adobe-courier-medium-r-normal--*-120-*-*-*-*-*-*");
mystring = "Testing";
text = new(GtkText);
text.width = 100;
text.height = 50;
text.insert(font, nil, nil, mystring, -1);

/* Use a function that has a void return typem, wih multiple return values. */
ret3 = gdk_text_extents(font, mystring, 14);
princ(string("\n*** Multiple return values:",
	     "\n\nThe C function gdk_text_extents() return type is: void",
	     "\nIts return values are: lbearing, rbearing, width, ascent, and descent.",
	     "\nThe type of all these return values is: int.",
	     "\n\nThe Gamma/GTK function gdk_text_extents(), when applied to",
	     "\nthe string 'Testing' in Courier 12 pt font returns: ", ret3, "\n\n"));

/* Create a box to display the text and button widgets. */
box1 = new(GtkVBox);
box1.spacing = 20;
box1.pack_start (text, TRUE, TRUE, 0);
box1.pack_start (button, TRUE, TRUE, 0);
  
button.signal("clicked",#gtk_main_quit());
window.add(box1);
window.show_all();

gtk_main();