[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Functions from guile-gtk
From: |
Rob Browning |
Subject: |
Re: Functions from guile-gtk |
Date: |
20 Aug 2001 18:27:23 -0500 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 |
Daniel Skarda <address@hidden> writes:
> mylib_func (this, and, that, MYLIB_FOO_MASK | MYLIB_BAR_MASK);
> mylib_another_func (something, MYLIB_FOOBAR);
>
> Scheme:
>
> (mylib-func this and that '(foo bar))
> (mylib-another-func something 'foo)
Hmm, so is it also possible to get the integer values at the Scheme
level for the various enumeration symbol translations? And can a
function like mylib-func also accept an integer as well as a symbol?
The reason I ask is that that's how g-wrap supports enumerations.
In g-wrap:
* Any function that returns an enum type at the C level will return
an integer at the Scheme level.
* Any function that takes an enum arg will take either a symbol or
an integer for that argument's value.
* There are val->sym and val->num converter functions created for
each enumeration type.
The val->sym function takes an integer or symbol and returns a
symbol, or all symbols if requested, that represent the given
enumeration value if there are any, or #f otherwise (so you can
use it for validation as well as conversion).
The val->num function takes an integer or symbol and returns an
integer that represents the given enumeration value if there is
one, or #f otherwise.
This arrangement means that you can get the highest performance if you
want to pre-convert your enum arguments, or you can just pass symbols
if you like. You can also do arbitrarily fancy bit operations on the
enumeration integer values if you want to before passing one in as an
argument.
Of course allowing raw ints means that it's possible to pass in
illegal enum values, but in the general case, given the ways people
use C enumerations and bit operations, I'm not sure that's something
you can really detect or prevent.
For example:
(let ((enum-arg (<my-app-color>-val->num 'green #f)))
(for-each
(lambda (item) (do-something item enum-arg))
list-of-thousands-of-items))
or
(let ((enum-arg (ash (logxor x y) z)))
(do-something enum-arg))
--
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG=1C58 8B2C FB5E 3F64 EA5C 64AE 78FE E5FE F0CB A0AD