Index: doc/example-scripts/rosetta-serialization.html =================================================================== diff -u -r24cb8f4bffd49c9375c1c64aa0610933b62511bb -rc4f449cb353be812ba6502ef8e9587e87881f59b --- doc/example-scripts/rosetta-serialization.html (.../rosetta-serialization.html) (revision 24cb8f4bffd49c9375c1c64aa0610933b62511bb) +++ doc/example-scripts/rosetta-serialization.html (.../rosetta-serialization.html) (revision c4f449cb353be812ba6502ef8e9587e87881f59b) @@ -1,882 +1,882 @@ - - - - - -Listing of doc/example-scripts/rosetta-serialization.tcl - - - - - -
-
-

Rosetta Example: Object serialization

-
- -
-
-
package req nx
-package req nx::serializer
-
-nx::Class create Being {
-  :property {alive:boolean true}
-}
-
-nx::Class create Animal -superclass Being {
-  :property name
-  :public method print {} {
-    puts "i am ${:name} alive ${:alive}"
-  }
-}
-
-

Demonstrating the behavior in a shell:

-

Create a few animals

-
-
-
% Animal new -name "Fido"
-% Animal new -name "Lupo"
-% Animal new -name "Kiki" -alive false
-

Print the created animals

-
-
-
% foreach i [Animal info instances] { $i print }
-

The loop prints:
- i am Kiki alive false
- i am Lupo alive true
- i am Fido alive true

-

Serialize the animals to a file

-
-
-
% set fpath [::nsf::tmpdir]/dump
-% set f [open $fpath w]
-% foreach i [Animal info instances] { puts $f [$i serialize] }
-% close $f
-

Destroy all animal instances:

-
-
-
% foreach i [Animal info instances] { $i destroy }
-% puts ===========
-

Print the existing animals (will print nothing)

-
-
-
% foreach i [Animal info instances] { $i print }
-% puts ===========
-

Load the animals again …

-
-
-
% source $fpath
-

and print it. The print output is the same as above

-
-
-
% foreach i [Animal info instances] { $i print }
-
-
-
-
-

- - - + + + + + +Listing of doc/example-scripts/rosetta-serialization.tcl + + + + + +
+
+

Rosetta Example: Object serialization

+
+ +
+
+
package req nx
+package req nx::serializer
+
+nx::Class create Being {
+  :property {alive:boolean true}
+}
+
+nx::Class create Animal -superclass Being {
+  :property name
+  :public method print {} {
+    puts "i am ${:name} alive ${:alive}"
+  }
+}
+
+

Demonstrating the behavior in a shell:

+

Create a few animals

+
+
+
% Animal new -name "Fido"
+% Animal new -name "Lupo"
+% Animal new -name "Kiki" -alive false
+

Print the created animals

+
+
+
% foreach i [Animal info instances] { $i print }
+

The loop prints:
+ i am Kiki alive false
+ i am Lupo alive true
+ i am Fido alive true

+

Serialize the animals to a file

+
+
+
% set fpath [::nsf::tmpdir]/dump
+% set f [open $fpath w]
+% foreach i [Animal info instances] { puts $f [$i serialize] }
+% close $f
+

Destroy all animal instances:

+
+
+
% foreach i [Animal info instances] { $i destroy }
+% puts ===========
+

Print the existing animals (will print nothing)

+
+
+
% foreach i [Animal info instances] { $i print }
+% puts ===========
+

Load the animals again …

+
+
+
% source $fpath
+

and print it. The print output is the same as above

+
+
+
% foreach i [Animal info instances] { $i print }
+
+
+
+
+

+ + +