[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
5.7.1.6 Top-level Structure of Guile-enabled Dia
Let’s assume that the pre-Guile Dia code looks structurally like this:
-
main ()
- do lots of initialization and setup stuff
- enter Gtk main loop
When you add Guile to a program, one (rather technical) requirement is
that Guile’s garbage collector needs to know where the bottom of the C
stack is. The easiest way to ensure this is to use
scm_boot_guile
like this:
-
main ()
- do lots of initialization and setup stuff
-
scm_boot_guile (argc, argv, inner_main, NULL)
-
inner_main ()
- define all SMOB types
-
export primitives to Scheme using
scm_c_define_gsubr
- enter Gtk main loop
In other words, you move the guts of what was previously in your
main
function into a new function called inner_main
, and
then add a scm_boot_guile
call, with inner_main
as a
parameter, to the end of main
.
Assuming that you are using SMOBs and have written primitive code as
described in the preceding subsections, you also need to insert calls to
declare your new SMOBs and export the primitives to Scheme. These
declarations must happen inside the dynamic scope of the
scm_boot_guile
call, but also before any code is run that
could possibly use them — the beginning of inner_main
is an
ideal place for this.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on April 20, 2013 using texi2html 5.0.