8000
Groveller,
Comment options
You must be logged in to vote
Comment options
You must be logged in to vote
Comment options
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji
reacted with thumbs down emoji
reacted with laugh emoji
reacted with hooray emoji
reacted with confused emoji
reacted with heart emoji
reacted with rocket emoji
reacted with eyes emoji
Groveller, cenum
, and allow-undeclared-values
#405
Unanswered
mister-walter
asked this question in
Q&A
Replies: 3 comments 3 replies
-
Just to be clear, given the following C code:
I would like the ability to achieve what the following
|
Beta Was this translation helpful? Give feedback.
0 replies
-
You can see here the code that parses `cenum` grovel directive and emits
the corresponding C code that in turn emits the defcenum form.
https://github.com/cffi/cffi/blob/master/grovel%2Fgrovel.lisp#L573
Let me know if you need help figuring the details out.
…On Mon, 3 Feb 2025, 21:20 Andrew Walter, ***@***.***> wrote:
Just to be clear, given the following C code:
typedef enum {
FOO_BAR,
FOO_BAZ,
FOO_QUX
} Foo;
Foo make_a_foo(int x) {
switch(x) {
case 0: return FOO_BAR;
case 1: return FOO_BAZ;
default: return FOO_QUX;
}
}
I would like the ability to achieve what the following defcenum does, but
using cenum and the Groveller instead.
(cffi:defcenum (Foo :int :allow-undeclared-values t)
(:bar 0)
(:baz 1))
(cffi:defcfun "make_a_foo" Foo
(x :int))
(make-a-foo 3) ;; => 2
—
Reply to this email directly, view it on GitHub
<#405 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAALFP6X53CTFQIR5FREYHL2N7MTNAVCNFSM6AAAAABWNAPWI2VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMBUG43TIMQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
-
@mister-walter If I understand correctly, you're trying to map any unkown value to a specific enum member. You can achieve that with a custom translator. I'm not convinced this should be part of the core CFFI. |
Beta Was this translation helpful? Give feedback.
8000
You must be logged in to vote
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using the Groveller to create bindings for some C enums. The C library I'm binding to may add additional enum values.
I would like to pass
:allow-undeclared-values t
to the underlyingdefcenum
call thatcenum
will end up expanding out into, so that if the library produces one of the new values (that doesn't appear in thecenum
call) the function that translates foreign values to Lisp values does not error out and simply returns the numeric value returned by the C function.What is the easiest way to do this? Do I need to write some custom Grovel syntax and arrange for it to be loaded prior to the running of the Groveller, or can I set the
allow-undeclared-values
field of the underlyingforeign-enum
instance after the fact?Happy to create a PR to update
cenum
so it allows the:allow-undeclared-values
keyword argument to be passed thru todefcenum
.Beta Was this translation helpful? Give feedback.
All reactions