def_mem(Actions)
{
- Animal method(init) (Animal self, str name);
+ void method(init) (Animal self, str name);
str method(talk) (Animal self);
};
char *name;
};
+Animal construct(Animal) (Animal self, str name)
+{
+ self->name = name;
+ return self;
+}
+
str cat_talk(Animal self)
{
return "Meow!";
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
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]));
}
}