[comp.lang.smalltalk] saving and recovering variables

sukumar@emx.utexas.edu (Sukumar Rathnam) (09/07/90)

The following is  hack that shows you how to save an 
object instance on to  afile

the instance can be resrtored by using the class message 
fooRestore to class FOO

!FOO methods !

saveObject:fooObj

"this experimental bit of code saves an object instance on a file
so that it can be restored later.
author: sukumar 8/27/90"

| tmp tmp1 objectSize allObj|


tmp :=  fooObj storeString.

tmp at:1 put:$ .
objectSize := tmp size.
tmp at:objectSize put: $ .

tmp1 := Disk newFile:
        (File
            fileName: 'foo'
            extension: (String with: $l with: $s with: $t)).
        tmp1 lineDelimiter: 13 asCharacter.

tmp1 nextPutAll:'!!FOO class methods !!';cr.
tmp1 nextPutAll:'fooRestore';cr.
tmp1 nextPutAll: '|tmp|';cr.
tmp1 nextPutAll: 'tmp := '.
tmp1 nextPutAll: tmp.
tmp1 nextPutAll: '.';cr.
tmp1 nextPutAll: '^tmp'.
tmp1 nextPutAll: '!! !!'.

tmp1 close.! !