X-Git-Url: http://git.harvie.cz/?p=svn%2FCll1h%2F.git;a=blobdiff_plain;f=demos%2Fobjects%2Fobjects-wiki.c;fp=demos%2Fobjects%2Fobjects-wiki.c;h=0000000000000000000000000000000000000000;hp=08403cb91af186a2a8830537b0a509af8217d5c2;hb=e63f1bc2438012b5f2f6592a474892501149af18;hpb=6a60bc82e8b8e6cccd0d4c2214a1f291662215f0 diff --git a/demos/objects/objects-wiki.c b/demos/objects/objects-wiki.c deleted file mode 100644 index 08403cb..0000000 --- a/demos/objects/objects-wiki.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "cll1.h" - -/* This is C<<1 rewrite of object polymorphism from - 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_interface(Animal,Actions) -{ - str method(talk) (Animal self); -}; - -def_obj(Animal) -{ - interface(Actions); - str name; -}; - -construct(Animal,Actions) (Animal self, str name) -{ - self->name = name; - return self; -} - -/* implementation of methods */ - -str catTalk(Animal self) -{ - return "Meow!"; -} - -str dogTalk(Animal self) -{ - return "Arf! Arf!"; -} - -/* registration of methods to object interface */ - -Actions catActions(void) -{ - Get_mem(this, Actions); - - this->talk = catTalk; - return this; -} - -Actions dogActions(void) -{ - Get_mem(this, Actions); - - this->talk = dogTalk; - return this; -} - -/* usage of objects inside C<<1 program */ - -program -{ - int i; - Animal animal[3]; - Actions cat = catActions(); - Actions dog = dogActions(); - - 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) - { - print(animal[i]->name, ":", _(talk, animal[i])); - } - -}