Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Object-serialization/Zkl/object-serialization.zkl
Normal file
26
Task/Object-serialization/Zkl/object-serialization.zkl
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
class [static] ARootClass{ // A top level class, no instances
|
||||
class A{ self.println(" constructor"); } // a regular class
|
||||
class B(A){ // ditto
|
||||
var x;
|
||||
fcn init(x=123){ self.x=x }
|
||||
fcn toString{ "x is "+x }
|
||||
}
|
||||
}
|
||||
|
||||
ARootClass.B(456).println(); // create an instance
|
||||
// prints:
|
||||
Class(A) constructor
|
||||
x is 456
|
||||
|
||||
f:=File("object.dat","wb");
|
||||
Compiler.Asm.writeRootClass(ARootClass,f); // serialize to file
|
||||
f.close();
|
||||
|
||||
f:=File("object.dat","rb");
|
||||
rc:=Compiler.Asm.readRootClass(f); // read and re-create
|
||||
// prints (readRootClass calls all constructors by default):
|
||||
Class(A) constructor
|
||||
f.close();
|
||||
rc.B().println(); // create a new instance of B
|
||||
// prints:
|
||||
x is 123
|
||||
Loading…
Add table
Add a link
Reference in a new issue