#3 FINALY !!! objects-wiki.c compiles (with -Wall) and runs !
[svn/Cll1h/.git] / demos / objects / objects-wiki.c
index 127f959d096b9e74cc32483389f5767cb4af539a..50e1288f2d82cd9fd58a158991751649d7a12beb 100644 (file)
@@ -1,48 +1,50 @@
 #include "cll1.h"
 
 /* This is C<<1 rewrite of object polymorphism from
-   http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming */
-
-def_type(Animal);
+   http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming
+   
+   Of course there are easier ways to do the same thing... :-) 
+   (G)2008 xChas */
 
 def_mem(Actions)
 {
- void method(init) (Animal self, str name);
- str method(talk) (Animal self);
+ str method(talk) (anonymous self);
 };
 
-def_obj(Animal)
+def_mem(Animal)
 {
  interface(Actions);
  char *name;
 };
 
-Animal construct(Animal) (Animal self, str name)
+construct(Animal) (Animal self, str name)
 {
  self->name = name;
  return self;
 }
 
-str cat_talk(Animal self)
+str cat_talk(anonymous self)
 {
  return "Meow!";
 }
 
-str dog_talk(Animal self)
+str dog_talk(anonymous self)
 {
  return "Arf! Arf!";
 }
 
 Actions cat_actions(void)
 {
- Actions this=get_mem(Actions);
+ Get_mem(this,Actions);
+
  this->talk = cat_talk;
  return this;
 }
 
 Actions dog_actions(void)
 {
- Actions this=get_mem(Actions);
+ Get_mem(this,Actions);
+
  this->talk = dog_talk;
  return this;
 }
@@ -54,12 +56,12 @@ program
  Actions cat = cat_actions();
  Actions dog = dog_actions();
 
- animal[0] = get_obj(Animal, cat, "Missy");
- animal[1] = get_obj(Animal, cat, "Mr. Bojangles");
- animal[2] = get_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]));
+  print(animal[i]->name,":",_(talk,animal[i]));
  }
 }
This page took 0.160678 seconds and 4 git commands to generate.