www.delorie.com/gnu/docs/smalltalk/gst_39.html   search  
 
Buy GNU books!


GNU Smalltalk User's Guide

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.8 Using the Smalltalk environment as an extension library

If you are reading this chapter because you are going to write extensions to GNU Smalltalk, this section won't probably interest you. But if you intend to use GNU Smalltalk as a scripting language or an extension language for your future marvellous software projects, you might be interest.

How to initialize GNU Smalltalk is most briefly and easily explained by looking at GNU Smalltalk's own source code. For this reason, here is a snippet from `main.c'.

 
/* From main.c */
int main(argc, argv)
int     argc;
char    **argv;
{
  gst_smalltalk_args(argc, argv);
  gst_init_smalltalk();
  gst_top_level_loop();

  exit(0);
}

Your initialization code will be almost the same as that in GNU Smalltalk's main(), with the exception of the call to gst_top_level_loop. All you'll have to do is to pass some arguments to the GNU Smalltalk library via gst_smalltalk_args, and then call gst_init_smalltalk.

Note that gst_init_smalltalk will likely take some time (from a second to 30-40 seconds), because it has to check if the image file must be be rebuilt and, if so, it reloads and recompiles the 37000 lines of Smalltalk code in a basic image. To avoid this check, pass a `-I' flag:

 
char myArgv[][] = { "-I", "myprog.im", nil };
int myArgc;
/* ... */
myArgc = sizeof(myArgv) / sizeof (char *) - 1;
smalltalkArgs(myArgc, myArgv);

If you're using GNU Smalltalk as an extension library, you might also want to disable the two ObjectMemory class methods, quit and quit: method. I advice you not to change the Smalltalk kernel code. Instead, in the script that loads your extension classes add these two lines:

 
ObjectMemory class compile: 'quit        self shouldNotImplement'!
ObjectMemory class compile: 'quit: n     self shouldNotImplement'!

which will effectively disable the two offending methods. Other possibilities include using atexit (from the C library) to exit your program in a less traumatic way, or redefining these two methods to exit through a call out to a C routine in your program.

Also, note that it is not a problem if you develop the class libraries for your programs within GNU Smalltalk's environment without defineCFunc-ing your own C call-outs, since GNU Smalltalk recalculates the addresses of the C call-outs every time it is started.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003