Make GetKey(win, KEY_ESCAPE) == PRESS
work
#225
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GetKey
is defined to return aBool
GLFW.jl/src/glfw3.jl
Line 648 in e8d5815
, but in the documentation it is defined as returning
PRESS
orRELEASE
. In C that doesn't matter because true, false PRESS and RELEASE are all integers and RELEASE is equal to false. But in Julia these are different types and so e.g.GLFW.GetKey(window, GLFW.KEY_ESCAPE)) == GLFW.PRESS
will always return false.This breaks the example in the Readme of GLAbstraction.jl:
The method added in this PR tells Julia how to compare an
Action
and aBool
so that code callingGetKey
as documented will work as expected, while also not breaking existing code that expects GetKey to return aBool
(e.g. the code in #163).Julia will do slightly more work when comparing
Bool
andAction
than when comparing twoBool
s because it will expand the Bool to 32 bits first. This could be avoided by defining the basetype of theAction
enum asUInt8
, but that would be a breaking change if arrays ofAction
are ever passed to C (I don't think they would be, but idk).I tried to persuade Julia to omit the expansion to 32 bits, but I couldn't find anything that worked. Closest was
b == unsafe_trunc(Bool, a)
, but that still emits more instructions than comparing twoBool
s.