GST Script

Smalltalk by example: Creating an executable image {{Category:GNU Smalltalk]]

Introduction

The idea of having smalltalk run self-contained images and building your program from within the running image. Although higly flexible and probably the way of the future, it doesn't seem to interact with the other programs at the moment.

This example shows you how to dump a running image in GNU Smalltalk, so you can run the image like a program. Code

This is an example of the 'echo' program. It will print the given arguments to the stdout. Please note that this is a stripped down version of the real GNU echo and doesn't support the same arguments. This code was written by Paolo Bonzini in reply to a question on the GNU Smalltalk help mailinglist.

First a subclass called EchoMain is created with a main function accepting the program arguments. The code then puts all arguments on the Transcript (stdout by default), ending it with a newline. Finally the script will register the EchoMain class to the ObjectMemory and then dump a snapshot of the image in the file echo.im. Creating the image and running it

The script will dump itself, so just run gst echo.st and it will create an echo.im file. Then use chmod a+x echo.im to make the image executable. This will then allow you to do ./echo.im hello world and the main function of the EchoMain class will put 'hello' and 'world' on the Transcript.

Back to GST by example