Create a set of data types based upon inheritance. Each data type or class should have a print command that displays the contents of an instance of that class to standard output. Create instances of each class in your inheritance hierarchy and display them to standard output. Write each of the objects to a file named objects.dat in binary form using serialization or marshalling. Read the file objects.dat and print the contents of each serialized object.

/* Object serialization, in Neko */
 
var file_open = $loader.loadprim("std@file_open", 2)
var file_write = $loader.loadprim("std@file_write", 4)
var file_read = $loader.loadprim("std@file_read", 4)
var file_close = $loader.loadprim("std@file_close", 1)
 
var serialize = $loader.loadprim("std@serialize", 1)
var unserialize = $loader.loadprim("std@unserialize", 2)
 
/* Inheritance by prototype */
proto = $new(null)
proto.print = function () { $print(this, "\n") }
 
obj = $new(null)
obj.msg = "Hello"
obj.dest = $array("Town", "Country", "World")
 
$objsetproto(obj, proto)
$print("Original:\n")
obj.print()
 
/* Serialize the object */
var thing = serialize(obj)
var len = $ssize(thing)
 
/* To disk */
var f = file_open("object-serialization.bin", "w")
file_write(f, thing, 0, len)
file_close(f)
 
/* Load the binary data into a new string space */
f = file_open("object-serialization.bin", "r")
var buff = $smake(len)
file_read(f, buff, 0, len)
file_close(f)
 
/* Unserialize the object into a new variable */
var other = unserialize(buff, $loader)
$print("deserialized:\n")
other.print()