2024-10-04 10:29:55 +02:00
|
|
|
function init_animal( byref self )
|
|
|
|
|
self.+yell := @animal_yell;
|
2018-02-04 16:08:03 +01:00
|
|
|
endfunction
|
2024-10-04 10:29:55 +02:00
|
|
|
function animal_yell( byref self )
|
|
|
|
|
print( self.text.call( self ) );
|
2018-02-04 16:08:03 +01:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function init_cat()
|
2024-10-04 10:29:55 +02:00
|
|
|
var cat := struct;
|
|
|
|
|
init_animal( cat );
|
|
|
|
|
cat.+text := @cat_text;
|
2018-02-04 16:08:03 +01:00
|
|
|
return cat;
|
|
|
|
|
endfunction
|
2024-10-04 10:29:55 +02:00
|
|
|
function cat_text( byref self )
|
2018-02-04 16:08:03 +01:00
|
|
|
return "miau";
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function init_dog()
|
2024-10-04 10:29:55 +02:00
|
|
|
var dog := struct;
|
|
|
|
|
init_animal( dog );
|
|
|
|
|
dog.+text := @dog_text;
|
|
|
|
|
dog.+angry := 0;
|
2018-02-04 16:08:03 +01:00
|
|
|
return dog;
|
|
|
|
|
endfunction
|
2024-10-04 10:29:55 +02:00
|
|
|
function dog_text( byref self )
|
|
|
|
|
if ( self.angry )
|
2018-02-04 16:08:03 +01:00
|
|
|
return "ggggrrr";
|
|
|
|
|
endif
|
|
|
|
|
return "wuff";
|
|
|
|
|
endfunction
|
|
|
|
|
|
2024-10-04 10:29:55 +02:00
|
|
|
var dog := init_dog();
|
|
|
|
|
dog.yell.call( dog );
|
|
|
|
|
dog.angry := 1;
|
|
|
|
|
dog.yell.call( dog );
|
2018-02-04 16:08:03 +01:00
|
|
|
|
2024-10-04 10:29:55 +02:00
|
|
|
var cat := init_cat();
|
|
|
|
|
cat.yell.call( cat );
|