Ian.Piumarta at inria.fr
Wed Sep 6 18:12:44 UTC 2000
> perhaps if you make a hello world example I'll get it.
Oops, the FM isn't in releases prior to 2.8.3 -- scratch that last
piece of advice. Here are the relevant bits of the FM:
squeak [ option... ] [ image ] [ script [ argument... ] ]
The image argument can be followed by a script name. This
is the name of a `document' that should contain Smalltalk
code to be executed on startup. The document can be
either the name of a file or a URL starting with `http:'.
Any arguments that appear after the script name are
ignored, but are made available to the script from within
Squeak via the method getSystemAttribute:. (See the sec-
tion SCRIPTS below.)
If image is given as `--' then squeak bahaves as if image
was not specified. This is useful to specify a script
without specifying an explicit image.
Squeak can load and execute a `script' file containing
Smalltalk code at startup. The name of the file should be
given as the script argument to squeak. For example,
assuming that the image `foo.image' contains an open Tran-
script window, then the following represents the `hello
world' program for Squeak:
Transcript cr; show: 'Hello, world'.
If this script is in a file called `hello.sq', then it
could be run like this:
squeak foo.image hello.sq
It is also possible to make `self interpreting' scripts by
adding an `interpreter line' to the start of the script.
The `hello.sq' file could be changed to
Transcript cr; show: 'Hello, world'.
and then made executable with
chmod +x hello.sq
and then invoked by running the script file directly:
If any arguments are present after the script name then
they can be retrieved from within the script using the
Smalltalk getSystemAttribute: n
where n is the index of the argument, starting at 3 for
the first argument. (See the method comment for
in the image for an explanation of the meanings of the
As an example of this, here is the `echo' program written
as a Squeak script:
"Echo arguments to the Transcript."
| i a |
i := 2.
[(a := Smalltalk getSystemAttribute: (i := i + 1))
whileTrue: [Transcript space; show: a].
When run as
./echo.sq one two three
this would print `one two three' in the Transcript window.
Needless to say, the above will break horribly without the UnixDocFile
changes that I posted an hour ago.
> And I'll also appreciate if you spell out the details of how to make an
> image with the #! in the beginning, is there a handy way to get it into
> the image from inside Squeak?
This isn't as straightforward as it sounds, since there are (or at
least there were) two kinds of images floating around: those that have
a 512-byte remnant (left over from their days as HFS files) before the
real data, and those that potentially don't. If you've got an image
that doesn't then I don't recommend trying to add an interpreter line
to the front of it.
You could pretty easily write some Squeak to find out if the header is
there or not by looking in the image loading code (which skips over
the header, if it finds one).
For images that have the header, it's pretty easy to add the
interpreter line in Squeak. After saving the image: open it as an old
binary file, dump
#!<full-path-to-vm> <any-`-<option>'s-you-like> <Character cr>
in the beginning, then close it. You can get at <full-path-to-vm>
through one of the system attributes.
 Which answers Bert's question from last week regarding whether we
shouldn't stop insisting on absolute paths (and use whatever paths
[including relative] were given on the command line) to the various
files (to avoid problems with broken implementations of realpath(),
like the one in GNU/Linux [heh, heh ;-]).
More information about the Squeak-dev