From: Olivier Dion via General Guile related discussions <guile-user@gnu.org>
To: guile-user@gnu.org
Subject: exit-hook never executed
Date: Thu, 22 Sep 2022 12:25:45 -0400 [thread overview]
Message-ID: <87r103v0ja.fsf@laura> (raw)
Hi,
`exit-hook' seems to only be executed when in a REPL. Is there a way for
it to be executed at the end of a none interactive program?
My intend here is that I have a module that load a foreign extension and
initialize its runtime so that other modules of that extension can be
used. I then add a hook for finalizing the extension, which is
important to save data.
Here's the snippet:
--8<---------------cut here---------------start------------->8---
(define-module (jami)
#:use-module (system foreing-library))
(let* ((libjami (load-foreign-library "libguile-jami"))
(init (foreign-library-function libjami "init"))
(fini (foreign-library-function libjami "fini")))
(init)
(add-hook! exit-hook fini))
--8<---------------cut here---------------end--------------->8---
So I guess the trivial solution would be to ask the user to manually
call the `init' and `fini' procedure before using any procedures of the
extension.
Something like this:
--8<---------------cut here---------------start------------->8---
(define-syntax-rule (with-jami body body* ...)
(dynamic-wind
init
(lambda () body body* ...)
fini))
--8<---------------cut here---------------end--------------->8---
But it would be nice to a have a hook for finalization like `exit-hook'
that is hidden from the user.
Though?
--
Olivier Dion
oldiob.dev
next reply other threads:[~2022-09-22 16:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-22 16:25 Olivier Dion via General Guile related discussions [this message]
[not found] <87tu4okh8q.fsf@laura>
2022-09-30 15:48 ` exit-hook never executed Jean Abou Samra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r103v0ja.fsf@laura \
--to=guile-user@gnu.org \
--cc=olivier.dion@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).