]> git.draconx.ca Git - gob-dx.git/blobdiff - examples/my-person.gob
Release 1.99.1
[gob-dx.git] / examples / my-person.gob
index f09b1511ae205a005ecbc213e18a892284389736..d895a629562f12c40b0c9a3b4625f13dfdc8ad5e 100644 (file)
@@ -1,4 +1,8 @@
-require 0.92.1
+requires 0.92.1
+
+/* This will work with an older version (0.92.1 specifically), if you want
+ * to see a version with automatic argument<->datamember linking, automatic
+ * initialization and destruction, look at my-person2.gob */
 
 %{
 #include <time.h>
@@ -12,20 +16,16 @@ class My:Person from Gtk:Object {
        public long dod; /* date of death as a time_t */
 
        private int rounds_in_shotgun; /* number of rounds in our shotgun */
-
+       
        argument POINTER (type char *) name
        get {
-               if(self->name)
-                       ARG = g_strdup(self->name);
-               else
-                       ARG = NULL;
+               /* note that g_strdup handles NULL correctly */
+               ARG = g_strdup(self->name);
        }
        set {
+               /* note that g_free and g_strdup handles NULL correctly */
                g_free(self->name);
-               if(ARG)
-                       self->name = g_strdup(ARG);
-               else
-                       self->name = NULL;
+               self->name = g_strdup(ARG);
        };
 
        argument LONG dob get { ARG = self->dob; } set { self->dob = ARG; };
@@ -80,6 +80,21 @@ class My:Person from Gtk:Object {
                self->_priv->rounds_in_shotgun--;
 
                /* death is imminent if we shoot oneself in the head */
-               death(self,(long)time(NULL));
+               death(self, (long)time(NULL));
+       }
+
+       /* override the destroy signal where we destroy data we need to free */
+       override (Gtk:Object)
+       void
+       destroy (Gtk:Object *self (check null type))
+       {
+               g_free(MY_PERSON(self)->name);
+               PARENT_HANDLER(self);
+       }
+
+       public GtkObject *
+       new(void)
+       {
+               return (GtkObject *)GET_NEW;
        }
 }