[GOODIE] Re: RE: Smalltalk scripting (was Re: jpython anyone?)
David T. Lewis
lewis at mail.msen.com
Tue Dec 12 21:25:35 UTC 2000
On Tue, Dec 12, 2000 at 10:50:24AM +0100, Marcel Weiher wrote:
> > From: "Lex Spoon" <lex at cc.gatech.edu>
>
> > They just think they want to. :)
>
> No, sometimes they *really* do want to.
At the risk of stifling further debate, here is a simple implementation.
A minor tweak to #fileInAnnouncing is all that is needed. You will want
to use a compiled headless VM with this.
Dave
-------------- next part --------------
'From Squeak2.8 of 13 June 2000 [latest update: #2359] on 12 December 2000 at 3:54:31 pm'!
"Change Set: SqueakScript
Date: 12 December 2000
Author: David T. Lewis
Make Squeak friendly for Unix command scripts. Squeak permits a
document file to be specified on the command line. If the first two
characters of the document file are '#!!' then the first line of the
file is skipped during a fileIn.
Note that in order to run the script in headless mode, is is necessary
to use a compiled headless VM rather than use the '-headless' option
with the regular VM. This is because the program specified in the
first line of a Unix script is permitted to have at most one command
line option, which must be used to specify the name of the image.
A simple Squeak command script might look like:
--- begin ---
#!!/usr/local/bin/headlessSqueakVM /usr/local/lib/headlessImage
| output |
output _ StandardFileStream fileNamed: '/dev/tty'.
output nextPutAll: 'hello world'; nextPut: Character lf.
output close
--- end ---
Preparing the image to use for scripting evaluate the following:
Smalltalk snapshot: true andQuit: true.
Smalltalk quitPrimitive.
To regain control of the image, start it using a script containing
a "self halt".
If your image includes OSProcess, then you can prepare a more
useful scripting image by evaluating:
Smalltalk snapshot: true andQuit: true.
Compiler evaluate: OSProcess readFromStdIn.
Smalltalk quitPrimitive.
If prepared this this way, the image will also accept Smalltalk commands
from standard input. For example:
echo OSProcess helloWorld | squeak
"!
!ReadWriteStream methodsFor: 'fileIn/Out' stamp: 'dtl 12/12/2000 14:14'!
fileInObjectAndCode
"This file may contain:
1) a fileIn of code
2) just an object in SmartReferenceStream format
3) both code and an object.
File it in and return the object. Note that self must be a FileStream or RWBinaryOrTextStream. Maybe ReadWriteStream incorporate RWBinaryOrTextStream?"
| refStream object |
self text.
self peek asciiValue = 4
ifTrue: [ "pure object file"
refStream _ SmartRefStream on: self.
object _ refStream nextAndClose]
ifFalse: [ "objects mixed with a fileIn"
((self peekFor: $#) and: [self peekFor: $!!])
ifTrue: [self nextLine]. "Unix command script, skip first line"
self fileIn. "reads code and objects, then closes the file"
object _ SmartRefStream scannedObject]. "set by side effect of one of the chunks"
SmartRefStream scannedObject: nil. "clear scannedObject"
^ object! !
More information about the Squeak-dev
mailing list
|