-
I'm using C3 to interop with Raylib and I've declared an enum with associated values like this: enum KeyboardKey : uint (inline uint code) {
NULL = 0,
APOSTROPHE = 39,
COMMA = 44,
MINUS = 45,
PERIOD = 46,
SLASH = 47,
ZERO = 48,
ONE = 49,
/* ... */
} Using extern fn bool _isKeyPressed(CInt key) @local @extern("IsKeyPressed");
fn bool isKeyPressed(KeyboardKey key) {
return _isKeyPressed(key);
} However, I can't use KeyboardKey.from_ordinal(1); // evaluates to KeyboardKey.APOSTROPHE I want to know if generating a switch-case statement at compile time would be possible. I want to be able to use runtime arguments. fn KeyboardKey keyFromKeycode(uint code) @local {
switch (code) {
default:
return KeyboardKey.NULL;
$for var $i = 0; $i < KeyboardKey.elements; ++$i:
var $e = KeyboardKey.values[$i];
var $c = $e.code;
case $c:
return $e;
$endfor
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can use fn KeyboardKey? keyFromKeycode(uint key_code) @local
{
return @enum_from_value(KeyboardKey, code, key_code);
} |
Beta Was this translation helpful? Give feedback.
You can use
@enum_from_value
: