-
Notifications
You must be signed in to change notification settings - Fork 16
How to avoid ambiguous enum values #55
Comments
This looks good! Do you have any insight on how stable this experimental feature is? It is at least in the main Nim manual, not the experimental one. Do you have any idea how exactly Have you tried just changing the function signature? My understanding is that |
I found this thread nim-lang/Nim#8066, looks like |
It's in the experimental manual (although it used to be in the manual before nim-lang/Nim#19173. According to https://forum.nim-lang.org/t/8404#54227 it looks promising. For |
The link you have referenced is to the normal manual. The experimental manual is https://nim-lang.org/docs/manual_experimental.html
I think this sounds good enough to migrate to this feature then. There were some CI issues for MacOS because it failed to install Nim 1.6.0 but hopefully now it is resolved, I will try one more time. Right now I'm working on #54 where I'm waiting for Windows testing from @enthus1ast and after that I think I will try to incorporate overloadable enums feature. |
Here's a list, I just made of every usage of enums in types and procs. I hope it's complete. # KeyboardKey
IsKeyPressed
IsKeyDown
IsKeyReleased
IsKeyUp
GetKeyPressed
SetExitKey
SetCameraPanControl
SetCameraAltControl
SetCameraSmoothZoomControl
SetCameraMoveControls
# GamepadButton
IsGamepadButtonPressed
IsGamepadButtonDown
IsGamepadButtonReleased
IsGamepadButtonUp
# GamepadAxis
GetGamepadAxisMovement
# MouseCursor
SetMouseCursor
# MouseButtonPressed
IsMouseButtonPressed
IsMouseButtonDown
IsMouseButtonReleased
IsMouseButtonUp
# Gesture
#SetGesturesEnabled set[Gesture] will not work, see https://forum.nim-lang.org/t/6271#38757 and https://forum.nim-lang.org/t/6383#39375 for the solution
IsGestureDetected
GetGestureDetected
# ConfigFlags
#SetConfigFlags set[ConfigFlags] will not work
IsWindowState
#SetWindowState same as above
ClearWindowState
# TraceLogLevel
TraceLogCallback
SetTraceLogLevel
TraceLog proc type
# CameraProjection
Camera3D.projection
# CameraMode
SetCameraMode
# NPatchLayout
NPatchInfo.layout
# BlendMode
BeginBlendMode
# MaterialMapIndex
SetMaterialTexture
# ShaderUniformDataType
SetShaderValue
SetShaderValueV
# ShaderLocationIndex
Shader.locs # RL_MAX_SHADER_LOCATIONS=32 !
# MaterialMapIndex
Material.maps # MAX_MATERIAL_MAPS=12 !
# PixelFormat
Image.format
Texture.format
LoadImageRaw
ImageFormat
GetPixelColor
SetPixelColor
GetPixelDataSize
# TextureFilter
SetTextureFilter
# TextureWrap
SetTextureWrap
# CubemapLayout
LoadTextureCubemap
# FontType
LoadFontData |
Another idea I got from the forum https://forum.nim-lang.org/t/8810 is to use distinct ints but put KeyboardKey in private/Key.nim , MouseButton in private/MouseButton.nim Edit: works but doesn't win us anything (except type safety which they all do) import MouseButton, Key
export MouseButton, Key
proc isKeyPressed*(key: KeyboardKey): bool = false file: import gamelib
echo isKeyPressed(Left)
#echo isKeyPressed(Key.Left) #this works Error:
Pros:
|
This would also work for duplicate values: type
MaterialMap = enum
Diffuse
ShaderLocationIndex = enum
Diffuse
template Albedo(_: typedesc[MaterialMap]): untyped = Diffuse
template Albedo(_: typedesc[ShaderLocationIndex]): untyped = Diffuse
proc foo(x: MaterialMap) = discard
foo(MaterialMap.Albedo) |
With the last update shortcuts like
isKeyDown(Right)
broke. We now need to specify the enum typeKeyboardKey.Right
, this is tedious, however there is a working solution. First we--experimental:overloadableEnums
, added in Nim v1.6..pure
needs to be removed from all enums. Last the type of the enum needs to be specified in the proc definition. i.e.:proc isKeyDown*(key: KeyboardKey): bool
andproc isMouseButtonDown*(button: MouseButton): bool
. Seems to work fine.The text was updated successfully, but these errors were encountered: