mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-24 12:20:20 +02:00
Add `scm_c_value_ref' to allow access to multiple returned values from C
Based on a patch by Julian Graham <julian@member.fsf.org> * libguile/values.c, libguile/values.h (scm_c_value_ref): New function. * doc/ref/api-control.texi (Multiple Values): Add documentation. * test-suite/standalone/test-scm-values.c: New test program. * test-suite/standalone/Makefile.am: Add test-scm-values test.
This commit is contained in:
parent
f0007cade0
commit
1ceeca0a76
5 changed files with 109 additions and 0 deletions
|
@ -67,6 +67,31 @@ print_values (SCM obj, SCM pwps)
|
|||
return SCM_UNSPECIFIED;
|
||||
}
|
||||
|
||||
SCM
|
||||
scm_c_value_ref (SCM obj, size_t idx)
|
||||
{
|
||||
if (SCM_LIKELY (SCM_VALUESP (obj)))
|
||||
{
|
||||
SCM values = scm_struct_ref (obj, SCM_INUM0);
|
||||
size_t i = idx;
|
||||
while (SCM_LIKELY (scm_is_pair (values)))
|
||||
{
|
||||
if (i == 0)
|
||||
return SCM_CAR (values);
|
||||
values = SCM_CDR (values);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
else if (idx == 0)
|
||||
return obj;
|
||||
|
||||
scm_error (scm_out_of_range_key,
|
||||
"scm_c_value_ref",
|
||||
"Too few values in ~S to access index ~S",
|
||||
scm_list_2 (obj, scm_from_unsigned_integer (idx)),
|
||||
scm_list_1 (scm_from_unsigned_integer (idx)));
|
||||
}
|
||||
|
||||
SCM_DEFINE (scm_values, "values", 0, 0, 1,
|
||||
(SCM args),
|
||||
"Delivers all of its arguments to its continuation. Except for\n"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue