Hi!
I'm using nimraylib_now to interface the raylib C library. There is a function called setConfigFlags that should be called with a bitmask or-ed set of flags (c-style).
I tried calling it the C-way:
setConfigFlags MSAA_4X_HINT | WINDOW_RESIZABLE
but then the compiler says:
/a/proj/oc/src/main.nim(11, 32) Error: type mismatch: got <ConfigFlags, ConfigFlags>
but expected one of:
proc `|`(a, b: typedesc): typedesc
first type mismatch at position: 1
required type for a: typedesc
but expression 'MSAA_4X_HINT' is of type: ConfigFlags
expression: MSAA_4X_HINT | WINDOW_RESIZABLE
I don't quite get what that means. Is this a generic overloaded operator that doesn't work with enums? Why is the error message so obtuse?
So then (a C-programmer as I am) I tried to cast to cuint:
setConfigFlags cuint(MSAA_4X_HINT) | cuint(WINDOW_RESIZABLE)
but that gave the same error as above.
The ConfigFlags type is an enum defined in the nimraylib_now wrapper:
type
ConfigFlags* {.size: sizeof(cint), pure.} = enum
FULLSCREEN_MODE = 0x00000002, ## Set to run program in fullscreen
WINDOW_RESIZABLE = 0x00000004, ## Set to allow resizable window
WINDOW_UNDECORATED = 0x00000008, ## Set to disable window decoration (frame and buttons)
... etc
at last I got it to work by trying "or" instead of "|":
setConfigFlags MSAA_4X_HINT or WINDOW_RESIZABLE
But I don't really know why it works since it is hard to find the documentation of "or" and "|". Can someone help a newbie and explain this?
Thanks, Henrik
Is this a generic overloaded operator that doesn't work with enums?
You asked for |, and the only | available is one that operates on typedescs. That single | is provided to you, along with its types and how those types differ from the types you gave it.
Why is the error message so obtuse?
You mean, why isn't it terse? Why is it giving you lots to read instead of a unique prompt to plug into stackoverflow? Because the terse error would be "You asked for a ConfigFlags|ConfigFlags and that doesn't exist.", and although that's helpful here where it simply doesn't exist, it's much less helpful when you're trying to use something that you know does exist, but you've got one of the types wrong.
it is hard to find the documentation of "or" and "|".
Use the stdlib search bar: https://nim-lang.org/docs/lib.html
searches for | and or will both find the system implementations that you used here.
Thanks for your input.
What is the "|" operator supposed to do?
The error message was obtuse until I understood that "|" was not a built-in :-) Sorry about that.
It was added in 2018 as part of some pre-pass checking of when statements, and is probably just there so that a check can believe that int|bool makes enough sense to not reject. In the same commit:
+proc compiles*(x: untyped): bool {.magic: "Compiles", noSideEffect, compileTime.} =
+ ## Special compile-time procedure that checks whether `x` can be compiled
+ ## without any semantic error.
+ ## This can be used to check whether a type supports some operation:
+ ##
+ ## .. code-block:: Nim
+ ## when compiles(3 + 4):
+ ## echo "'+' for integers is available"
+ discard