Skip to content
Chris Petersen edited this page Aug 6, 2013 · 4 revisions

The main.scm file contains the application source code. Code can be either straight-forward Scheme for console-based applications, or event loop based code for graphical applications. Event loop based applications need a main procedure call. The arguments to the call are handlers for initialization, event handling, termination, suspend and resume. For example, the following program creates a GUI with a red square box in the initialization call, and renders it in the event loop call:

(define gui #f)

(main
;; initialization
  (lambda (w h)
    (make-window 320 480)
    (glgui-orientation-set! GUI_PORTRAIT)
    (set! gui (make-glgui))
    (let* ((w (glgui-width-get))
           (h (glgui-height-get))
           (dim (min (/ w 2) (/ h 2))))
      (glgui-box gui (/ (- w dim) 2) (/ (- h dim) 2) dim dim Red))
)
;; events
  (lambda (t x y)
    (if (= t EVENT_KEYPRESS) (begin
      (if (= x EVENT_KEYESCAPE) (terminate))))
    (glgui-event gui t x y))
;; termination
  (lambda () #t)
;; suspend
  (lambda () (glgui-suspend))
;; resume
  (lambda () (glgui-resume))
)

Console programs doesn't need an event loop. The simplest possible application in console mode is:

(display "HelloWorld")

which just displays the text and exits. A more useful console program that provides access to the Gambit interpreter is:

(display "DemoConsole\n")
(let loop ()
  (with-exception-catcher (lambda (e)
    (for-each display
      (list (exception->string e) "\n")) #f)
    (lambda () (##repl-debug)))
  (loop))
Clone this wiki locally