]> git.draconx.ca Git - gob-dx.git/blob - examples/my-person2.gob
b7f23ed37e0d82710000294349583973943887a4
[gob-dx.git] / examples / my-person2.gob
1 requires 0.93.0
2
3 /* this file requires 0.93.0 as it uses some of the new features to reduce
4  * typing and generally make it easier to read I think.  Of course they're
5  * optional to use so use the my-person.gob as an example of not using them.
6  * These include data member initialization, automatic destructor calling
7  * and automatic argument<->data member linking */
8
9 %{
10 #include <time.h>
11 #include "my-person2.h"
12 #include "my-person2-private.h"
13 %}
14
15 class My:Person2 from Gtk:Object {
16         /* the name of the person */
17         public char *name = {g_strdup("Nobody")}
18                 destroywith g_free;
19         argument POINTER name stringlink;
20
21         /* date of birth as a time_t */
22         public long dob = 0;
23         argument LONG dob link;
24
25         /* date of death as a time_t */
26         public long dod = 0;
27         argument LONG dod link;
28
29         /* number of rounds in our shotgun */
30         private int rounds_in_shotgun = 0;
31
32         /* when the person gets born, sends out a signal, the caller
33            of the signal should provide the date of birth */
34         signal last NONE (LONG)
35         void
36         birth(self, long dob)
37         {
38                 self->dob = dob;
39         }
40         
41         /* when the person dies, sends out a signal, the caller
42            of the signal should provide the date of death */
43         signal last NONE (LONG)
44         void
45         death(self, long dod)
46         {
47                 self->dod = dod;
48         }
49
50         public
51         void
52         load_shotgun(self)
53         {
54                 /* add a round to our shotgun */
55                 self->_priv->rounds_in_shotgun++;
56         }
57
58         public
59         void
60         shoot_oneself_in_the_head(self)
61         {
62                 if(self->_priv->rounds_in_shotgun==0) {
63                         g_warning("No rounds in the shotgun!");
64                         return;
65                 }
66                 
67                 /* one round was fired */
68                 self->_priv->rounds_in_shotgun--;
69
70                 /* death is imminent if we shoot oneself in the head */
71                 death(self, (long)time(NULL));
72         }
73
74         public GtkObject *
75         new(void)
76         {
77                 return (GtkObject *)GET_NEW;
78         }
79 }