[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Newbie question on writing bindings.
From: |
Martin Grabmueller |
Subject: |
Re: Newbie question on writing bindings. |
Date: |
Tue, 17 Apr 2001 16:36:10 +0200 |
> From: Joel Smith <address@hidden>
> Date: Sat, 14 Apr 2001 21:59:27 +0000 (GMT)
>
> How do I write bindings for such functions? I thought about passing the
> various values as a list but that does not seem like the Right Thing to
> me. I also thought of using keyword arguments like this:
>
> (baz #:foo #t :#bar #t)
>
> But I don't know how to write a C routine to handle keyword arguments. I
> have looked at other guile code to see if anyone else has solved this
> problem but I could not find any examples of it. Surely I can't be the
> only person who wants to do this? ;-) Any help would be much appreciated!
I haven't tried to use keywords in Guile extensions yet, but I think
you would have to:
1. Define your primitive written in C to accept arbitrarily many arguments.
2. Go through the list of arguments when the function is called.
3. Check whether a given argument is a keyword, using SCM_KEYWORDP.
4. Extract the name of the keyword with SCM_KEYWORDSYM.
5. Act according to the name of the keyword. This could be done by
creating symbols in your C file (using SCM_SYMBOL) and using
SCM_EQ to compare the name of the keyword with the symbol.
But personally, I like it better to write the primitive `baz' in a way
that it can be called like
(baz 'foo 'bar)
and then checking all arguments, ORing a bit into an int variable
whenever the right symbol is encountered in the argument list, then
use the newly constructed integer to call into the C library. This is
the way I do it in my guile-gdbm bindings (available from
http://www.pintus.de/mgrabmue/guile/).
Hope that helps,
'martin