Subject:
[ruby-ffi] Re: New wiki page: Enums. Please improve and correct.
From:
Wayne Meissner
Date:
11/13/09 10:53 PM
To:
ruby-ffi@googlegroups.com


Excellent work!

I wouldn't call the first example (using constants), "BAD EXAMPLE",
since its still a valid way to do integer constants.  Its just not as
nice as the enum way.

btw, there are a couple of other ways to declare enums

1) Use typedef
  typedef enum(:a, :b, :c), :my_enum

That is the equivalent of enum :my_enum, [ :a, :b, :c ]

2) Assign the new Enum type to a constant
  MyEnum = enum(:a, :b, :c)


Not sure if those add any value, or would just clutter up the page
though.  Probably best left out, and in the realms of "if you really
need it, you can do it".

The second form however, is needed if you intend to use an enum as a
Struct field type, for the same reason you need to do that for e.g.
callbacks.  i.e. lexical scoping rules.

2009/11/14 John Croisant <jacius@gmail.com>:
>
> I've added a new page on the wiki, with information about using enums
> in FFI. This is mostly from my own investigations into the source code
> several months ago, but I'm not sure it's accurate, complete, or up to
> date. I'd love to have an FFI maintainer or expert check to make sure
> it's right, and maybe even add some more info. :-)
>
>  http://wiki.github.com/ffi/ffi/enums
>
> - John
>