X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmain.cc;h=7a524d77dc8b45295c838e9079195252a7dc123d;hb=87eedcd59f4082cb0841528ad5bc82cb1d1191e3;hp=508b4b8f5bae126bbd6fe911afb5f37d47f72f03;hpb=faf88ec6913fb74676ddc68e77b27b402ac756a3;p=lilypond.git diff --git a/lily/main.cc b/lily/main.cc index 508b4b8f5b..7a524d77dc 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -627,3 +627,25 @@ main (int argc, char **argv) /* Only reachable if GUILE exits. That is an error. */ return 1; } + +SCM atexit_list = SCM_EOL; + +LY_DEFINE (ly_atexit, "ly:atexit", + 2, 0, 0, (SCM proc, SCM args), + "Just before exiting, call the procedure given. " +"If this is called multiple times, the procedures are called " +"in LIFO order.") +{ + atexit_list = scm_cons (scm_cons (proc, args), atexit_list); + scm_gc_protect_object (atexit_list); + return SCM_UNSPECIFIED; +} + +LY_DEFINE (ly_do_atexit, "ly:do-atexit", + 0, 0, 0, (), + "Call the atexit procedures.") +{ + for (SCM s = atexit_list; scm_is_pair (s); s = scm_cdr (s)) + scm_apply_0 (scm_caar (s), scm_cdar (s)); + return SCM_UNSPECIFIED; +}