* Geting the value of a top level scheme value from C
@ 2014-01-24 16:54 Richard Shann
2014-01-24 17:06 ` Thompson, David
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Richard Shann @ 2014-01-24 16:54 UTC (permalink / raw)
To: guile-user
Given a C string that is the name of a Scheme variable what is the call
I need to make from C to get the value?
That is, in the Scheme I have
(define foo "bar")
Then in C I want to write
SCM bar = scm_var_c_get_val ("foo");//imaginary function name
strcmp ("bar", scm_to_locale_string (bar));
etc...
Richard Shann
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Geting the value of a top level scheme value from C
2014-01-24 16:54 Geting the value of a top level scheme value from C Richard Shann
@ 2014-01-24 17:06 ` Thompson, David
2014-01-24 17:07 ` Panicz Maciej Godek
2014-01-24 17:34 ` Mark H Weaver
2 siblings, 0 replies; 5+ messages in thread
From: Thompson, David @ 2014-01-24 17:06 UTC (permalink / raw)
To: richard; +Cc: Guile User
On Fri, Jan 24, 2014 at 11:54 AM, Richard Shann <richard@rshann.plus.com> wrote:
> Given a C string that is the name of a Scheme variable what is the call
> I need to make from C to get the value?
>
> That is, in the Scheme I have
>
> (define foo "bar")
>
> Then in C I want to write
>
> SCM bar = scm_var_c_get_val ("foo");//imaginary function name
>
> strcmp ("bar", scm_to_locale_string (bar));
>
> etc...
>
> Richard Shann
Hello Richard,
I think 'scm_public_ref' is what you want.
See the manual for further explanation and other procedures in case I
picked the wrong one. ;)
http://www.gnu.org/software/guile/manual/html_node/Accessing-Modules-from-C.html#Accessing-Modules-from-C
- Dave
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Geting the value of a top level scheme value from C
2014-01-24 16:54 Geting the value of a top level scheme value from C Richard Shann
2014-01-24 17:06 ` Thompson, David
@ 2014-01-24 17:07 ` Panicz Maciej Godek
2014-01-24 17:34 ` Mark H Weaver
2 siblings, 0 replies; 5+ messages in thread
From: Panicz Maciej Godek @ 2014-01-24 17:07 UTC (permalink / raw)
To: richard; +Cc: guile-user@gnu.org
2014/1/24 Richard Shann <richard@rshann.plus.com>:
> Given a C string that is the name of a Scheme variable what is the call
> I need to make from C to get the value?
[...]
i think it is all well described here:
http://www.gnu.org/software/guile/manual/html_node/Accessing-Modules-from-C.html
however, note that according to the manual, you need to free the
result of scm_to_locale_string manually, in order not to get a memory
leak (because apparently it isn't magaged by the bdw gc), so passing
the result directly to strcmp is not a fortunate idea.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Geting the value of a top level scheme value from C
2014-01-24 16:54 Geting the value of a top level scheme value from C Richard Shann
2014-01-24 17:06 ` Thompson, David
2014-01-24 17:07 ` Panicz Maciej Godek
@ 2014-01-24 17:34 ` Mark H Weaver
2014-01-24 17:49 ` Richard Shann
2 siblings, 1 reply; 5+ messages in thread
From: Mark H Weaver @ 2014-01-24 17:34 UTC (permalink / raw)
To: richard; +Cc: guile-user
Richard Shann <richard@rshann.plus.com> writes:
> Given a C string that is the name of a Scheme variable what is the call
> I need to make from C to get the value?
>
> That is, in the Scheme I have
>
> (define foo "bar")
>
> Then in C I want to write
>
> SCM bar = scm_var_c_get_val ("foo");//imaginary function name
SCM bar = scm_variable_ref (scm_c_lookup ("foo"));
For better efficiency, do this just once, after 'foo' has been defined:
SCM foo_var = scm_c_lookup ("foo");
and henceforth just do:
SCM bar = scm_variable_ref (foo_var);
Mark
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Geting the value of a top level scheme value from C
2014-01-24 17:34 ` Mark H Weaver
@ 2014-01-24 17:49 ` Richard Shann
0 siblings, 0 replies; 5+ messages in thread
From: Richard Shann @ 2014-01-24 17:49 UTC (permalink / raw)
To: Mark H Weaver; +Cc: guile-user
Thanks for all the replies - sorry I didn't spot that section of the
manual (perhaps because it came under "Using modules" and I haven't
dipped my toes in that stuff).
I have it working now.
Richard
On Fri, 2014-01-24 at 12:34 -0500, Mark H Weaver wrote:
> Richard Shann <richard@rshann.plus.com> writes:
>
> > Given a C string that is the name of a Scheme variable what is the call
> > I need to make from C to get the value?
> >
> > That is, in the Scheme I have
> >
> > (define foo "bar")
> >
> > Then in C I want to write
> >
> > SCM bar = scm_var_c_get_val ("foo");//imaginary function name
>
> SCM bar = scm_variable_ref (scm_c_lookup ("foo"));
>
> For better efficiency, do this just once, after 'foo' has been defined:
>
> SCM foo_var = scm_c_lookup ("foo");
>
> and henceforth just do:
>
> SCM bar = scm_variable_ref (foo_var);
>
> Mark
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-01-24 17:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-24 16:54 Geting the value of a top level scheme value from C Richard Shann
2014-01-24 17:06 ` Thompson, David
2014-01-24 17:07 ` Panicz Maciej Godek
2014-01-24 17:34 ` Mark H Weaver
2014-01-24 17:49 ` Richard Shann
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).