polserver/testsuite/escript/classes/test.src
Kevin Eady 0fa1b893a0 Update core-changes, break-changes for classes support (#719)
* Format testsuite escript

* Format testsuite pol

* Update docs
Switch "attributes" to "members" to better align with Escript terms.

* Add core-changes, breaking-changes
2024-10-10 18:06:04 +02:00

27 lines
794 B
Text

class BaseClass()
function BaseClass( this )
endfunction
endclass
class Animal( BaseClass )
var staticVar := Print( 1 + 2 ) ?: "value for static after printing";
function Animal( this, name )
this.name := name;
print( $"Animal constructor staticVar={staticVar}" );
return; // can have empty returns
endfunction
endclass
// Compile-time constructor call. Creates a class instance, and attachs vtable
var compile_obj := Animal( "compile-time ctor call" );
print( $"compile_obj={compile_obj}" );
// Run-time constructor call. Does not attach vtable in this scenario, but calls the user function
var runtime_obj := dictionary{};
@Animal( runtime_obj, "runtime ctor call" );
print( $"runtime_obj={runtime_obj}" );
print( $"Global scope staticVar={Animal::staticVar}" );