Previous: Running Image Files, Up: Image Files

13.8 Modifying the Startup Sequence

You can add your own initialization to the startup sequence of an image through the deferred word 'cold. 'cold is invoked just before the image-specific command line processing (i.e., loading files and evaluating (-e) strings) starts.

A sequence for adding your initialization usually looks like this:

         Defers 'cold \ do other initialization stuff (e.g., rehashing wordlists)
         ... \ your stuff
     ; IS 'cold

After 'cold, Gforth processes the image options (see Invoking Gforth), and then it performs bootmessage, another deferred word. This normally prints Gforth's startup message and does nothing else.

So, if you want to make a turnkey image (i.e., an image for an application instead of an extended Forth system), you can do this in two ways:

In either case, you probably do not want the word that you execute in these hooks to exit normally, but use bye or throw. Otherwise the Gforth startup process would continue and eventually present the Forth command line to the user.

'cold              gforth       “tick-cold”

Hook (deferred word) for things to do right before interpreting the OS command-line arguments. Normally does some initializations that you also want to perform.

bootmessage              gforth       “bootmessage”

Hook (deferred word) executed right after interpreting the OS command-line arguments. Normally prints the Gforth startup message.