My objective was to provide a Nim api for sdl2 bindings. The problem is C enums 
[starting from 
0](https://github.com/zielmicha/SDL2/blob/master/include/SDL_render.h) when are 
converted to Nim, the resulting sets are wrong.

[Here](https://play.nim-lang.org/#ix=2jWv) is an example to tinker

I have two solutions

1) A const empty set `FlipNone`, replacing the the enum's first value, 
(basically omitting it). .. code-block:: nim

> type
>     
> 
> RendererFlip {.pure.} = enum
>     FlipHorizontal # flip horizontally FlipVertical # flip vertically
> 
> const FlipNone: set[RendererFlip] = {} # Do not flip proc copyEx(stuff... 
> flip: set[RendererFlip] = FlipNone)

  1. Use a converter as mentioned in the manual

type
    

RendererFlip {.pure.} = enum
    FlipNone = 0 # Do not flip FlipHorizontal # flip horizontally FlipVertical 
# flip vertically

proc toNum(f: set[RendererFlip]): int = cast[cint](f) shr 1




The [manual](https://nim-lang.org/docs/manual.html#set-type-bit-fields) 
mentions `distinct cint` but has no example.

Which one should I use and why? 

Reply via email to