some unfinished work
[svn/Cll1h/.git] / demos / objects / objects-wiki.c
index e55cb7439a3a2ebcfb6612ee3cac2bd811ad8f10..127f959d096b9e74cc32483389f5767cb4af539a 100644 (file)
@@ -7,7 +7,7 @@ def_type(Animal);
 
 def_mem(Actions)
 {
Animal method(init) (Animal self, str name);
void method(init) (Animal self, str name);
  str method(talk) (Animal self);
 };
 
@@ -17,6 +17,12 @@ def_obj(Animal)
  char *name;
 };
 
+Animal construct(Animal) (Animal self, str name)
+{
+ self->name = name;
+ return self;
+}
+
 str cat_talk(Animal self)
 {
  return "Meow!";
@@ -27,22 +33,18 @@ str dog_talk(Animal self)
  return "Arf! Arf!";
 }
 
-Animal animal_init(Animal self, str name)
-{
- self->name = name;
- return self;
-}
-
-Actions cat_actions(Actions this)
+Actions cat_actions(void)
 {
this->init = animal_init;
Actions this=get_mem(Actions);
  this->talk = cat_talk;
+ return this;
 }
 
-Actions dog_actions(Actions this)
+Actions dog_actions(void)
 {
this->init = animal_init;
Actions this=get_mem(Actions);
  this->talk = dog_talk;
+ return this;
 }
 
 program
@@ -52,13 +54,12 @@ program
  Actions cat = cat_actions();
  Actions dog = dog_actions();
 
- animal[0] = init_obj(Animal, Actions, cat)
-  "Missy");
- animal[1] = init_obj(Animal, cat, "Mr. Bojangles");
- animal[2] = init_obj(Animal, dog, "Lassie"); 
+ animal[0] = get_obj(Animal, cat, "Missy");
+ animal[1] = get_obj(Animal, cat, "Mr. Bojangles");
+ animal[2] = get_obj(Animal, dog, "Lassie");
 
  for_range(i, 0, 2)
  {
-  printf("%s: %s\n", animal[i].name, _(talk, animal[i]));
+  printf("%s: %s\n", animal[i]->name, _(talk, animal[i]));
  }
 }
This page took 0.135913 seconds and 4 git commands to generate.