GNU Info

Info Node: (guile.info)Guile Initialization Functions

(guile.info)Guile Initialization Functions


Next: A Sample Guile Main Program Up: Linking Programs With Guile
Enter node , (file) or (file)node

Guile Initialization Functions
------------------------------

To initialize Guile, use this function:

 - Function: void scm_boot_guile (int ARGC, char **ARGV, void
          (*MAIN_FUNC) (), void *CLOSURE)
     Initialize the Guile Scheme interpreter.  Then call MAIN_FUNC,
     passing it CLOSURE, ARGC, and ARGV.  MAIN_FUNC should do all the
     work of the program (initializing other packages, defining
     application-specific functions, reading user input, and so on)
     before returning.  When MAIN_FUNC returns, call `exit (0)';
     `scm_boot_guile' never returns.  If you want some other exit value,
     have MAIN_FUNC call exit itself.

     `scm_boot_guile' arranges for the Scheme `command-line' function
     to return the strings given by ARGC and ARGV.  If MAIN_FUNC
     modifies ARGC or ARGV, it should call `scm_set_program_arguments'
     with the final list, so Scheme code will know which arguments have
     been processed.

     `scm_boot_guile' establishes a catch-all error handler which prints
     an error message and exits the process.  This means that Guile
     exits in a coherent way if a system error occurs and the user
     isn't prepared to handle it.  If the user doesn't like this
     behavior, they can establish their own universal catcher in
     MAIN_FUNC to shadow this one.

     Why must the caller do all the real work from MAIN_FUNC?  Guile's
     garbage collector assumes that all local variables which reference
     Scheme objects will be above `scm_boot_guile''s stack frame on the
     stack.  If you try to manipulate Scheme objects after this function
     returns, it's the luck of the draw whether Guile's storage manager
     will be able to find the objects you allocate.  So,
     `scm_boot_guile' function exits, rather than returning, to
     discourage you from making that mistake.

One common way to use Guile is to write a set of C functions which
perform some useful task, make them callable from Scheme, and then link
the program with Guile.  This yields a Scheme interpreter just like
`guile', but augmented with extra functions for some specific
application -- a special-purpose scripting language.

In this situation, the application should probably process its
command-line arguments in the same manner as the stock Guile
interpreter.  To make that straightforward, Guile provides this
function:

 - Function: void scm_shell (int ARGC, char **ARGV)
     Process command-line arguments in the manner of the `guile'
     executable.  This includes loading the normal Guile initialization
     files, interacting with the user or running any scripts or
     expressions specified by `-s' or `-e' options, and then exiting.
     Note: Invoking Guile, for more details.

     Since this function does not return, you must do all
     application-specific initialization before calling this function.

     If you do not use this function to start Guile, you are
     responsible for making sure Guile's usual initialization files,
     `init.scm' and `ice-9/boot-9.scm', get loaded.  This will change
     soon.


automatically generated by info2www version 1.2.2.9