From: 宋文武 <iyzsong@envs.net>
To: Leon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de>
Cc: <guile-user@gnu.org>
Subject: Re: Calling user defined guile functions from C?
Date: Fri, 24 Nov 2023 18:50:07 +0800 [thread overview]
Message-ID: <87msv3o274.fsf@envs.net> (raw)
In-Reply-To: <CX69Z8VEXGGC.2O6N6Y5K4NF6N@stud.uni-goettingen.de> (Leon Henrik Plickat's message of "Thu, 23 Nov 2023 15:53:06 +0100")
Hello!
Leon Henrik Plickat <leonhenrik.plickat@stud.uni-goettingen.de> writes:
> [...]
>
> Must the program run in guile mode the entire time, or can I enter
> it only temporarily for eval'ing the script and calling the function?
I think 'scm_init_guile' is for the entire time, and 'scm_with_guile'
is for the temporarily usage.
> What is the canonical way of eval'ing a script to get a function
> definition from C?
Use 'scm_c_primitive_load' to load and eval a script, if the script
return a function as its last value, then it's done.
Else use 'scm_c_lookup' to get the function as a varaible.
> Can I check after eval'ing the script whether the function I want the
> user to define exists? Probably with scm_c_eval_string() again, but
> I wonder if there is some other more way that is considered to be
> better.
It seems 'scm_module_variable' returns '#f' when the variable binding
doesn't exist.
>
> I am working my way through the API reference, but decided to ask
> for some input in the meantime.
Procedures needed are described in manual section "6.18.10 Accessing
Modules from C". The flow are:
- Enter guile mode via 'scm_init_guile', 'scm_boot_guile', or 'scm_with_guile'.
- Load and eval script via 'scm_c_primitive_load'.
- Get SCM variables via 'scm_c_lookup', 'scm_module_variable'
- Dereference variables via 'scm_variable_ref' to procedures SCM.
- Call procedures via 'scm_call', 'scm_call_1, etc.
Hope it helps!
next prev parent reply other threads:[~2023-11-24 10:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-23 14:53 Calling user defined guile functions from C? Leon Henrik Plickat
2023-11-24 10:50 ` 宋文武 [this message]
2023-11-26 9:07 ` Leon Henrik Plickat
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=87msv3o274.fsf@envs.net \
--to=iyzsong@envs.net \
--cc=guile-user@gnu.org \
--cc=leonhenrik.plickat@stud.uni-goettingen.de \
/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).