Next: , Previous: Embedding SCM, Up: Operations


6.2.11 Callbacks

SCM now has routines to make calling back to Scheme procedures easier. The source code for these routines are found in rope.c.

— Function: int scm_ldfile (char *file)

Loads the Scheme source file file. Returns 0 if successful, non-0 if not. This function is used to load SCM's initialization file Init5e7.scm.

— Function: int scm_ldprog (char *file)

Loads the Scheme source file (in-vicinity (program-vicinity) file). Returns 0 if successful, non-0 if not.

This function is useful for compiled code init_ functions to load non-compiled Scheme (source) files. program-vicinity is the directory from which the calling code was loaded (see Vicinity).

— Function: SCM scm_evstr (char *str)

Returns the result of reading an expression from str and evaluating it.

— Function: void scm_ldstr (char *str)

Reads and evaluates all the expressions from str.

If you wish to catch errors during execution of Scheme code, then you can use a wrapper like this for your Scheme procedures:

     (define (srv:protect proc)
       (lambda args
         (define result #f)                  ; put default value here
         (call-with-current-continuation
          (lambda (cont)
            (dynamic-wind (lambda () #t)
                          (lambda ()
                            (set! result (apply proc args))
                            (set! cont #f))
                          (lambda ()
                            (if cont (cont #f))))))
         result))

Calls to procedures so wrapped will return even if an error occurs.