polserver/testsuite/escript/classes/doc-sample-03.src
Kevin Eady 0988c17f29 Add classes documentation (#717)
* Add escript guide docs for classes

* Add ClassInstanceRef to objref docs

* Use objref.dot to generate svg
2024-10-10 18:06:04 +02:00

35 lines
695 B
Text

class Person()
function Person( this, name )
this.name := name;
endfunction
function Say( what )
Print( what );
endfunction
endclass
class Wizard( Person )
function Wizard( this, name )
super( name );
endfunction
function Attack( this )
Say( $"{this.name} casts a spell!" );
endfunction
endclass
class Fighter( Person )
function Fighter( this, name )
super( name );
endfunction
function Attack( this )
Say( $"{this.name} swings a sword!" );
endfunction
endclass
var gandalf := Wizard( "Gandalf" );
var aragorn := Fighter( "Aragorn" );
gandalf.Attack(); // Output: Gandalf casts a spell!
aragorn.Attack(); // Output: Aragorn swings a sword!