X-Git-Url: http://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/40647d7b7b7fbeae828e0a032a3c3a5f204cdfa8..c9914e54f16c3315d47040f4cca2d3788228c504:/examples/my-person.gob diff --git a/examples/my-person.gob b/examples/my-person.gob index 516ee3e..cad0672 100644 --- a/examples/my-person.gob +++ b/examples/my-person.gob @@ -1,6 +1,13 @@ +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 #include "my-person.h" +#include "my-person-private.h" %} class My:Person from Gtk:Object { @@ -10,32 +17,28 @@ class My:Person from Gtk:Object { private int rounds_in_shotgun; /* number of rounds in our shotgun */ - argument POINTER name + argument POINTER (type char *) name get { - if(self->name) - ARG = g_strdup(self->name); - else - ARG = NULL; + /* note that strdup handles NULL correctly */ + ARG = g_strdup(self->name); } set { + /* note that 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; }; argument LONG dod get { ARG = self->dod; } set { self->dod = ARG; }; - init(person) + init(self) { - person->name = g_strdup("Nobody"); - person->dob = 0; - person->dod = 0; + self->name = g_strdup("Nobody"); + self->dob = 0; + self->dod = 0; /* initially we have no rounds in the shotgun */ - person->_priv->rounds_in_shotgun = 0; + self->_priv->rounds_in_shotgun = 0; } /* when the person gets born, sends out a signal, the caller @@ -77,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; } }