Fiddle: enums?

Hi,

What's wrong with something like:

module MyLib
  extend Fiddle::Importer
  dlload "mylib.so"
  FOO = 1
  BAR = 2
  BAZ = 3
  extern "void func(int)"
end

MyLib.func(MyLib::BAR)

Somehow I haven't thought about using constants for the enum's values,
but yes, it is an option indeed. It doesn't look as rubyish as a

    MyLib.func(:bar)

would do, though, but I understand that this is something I have to
implement. Thank you for your suggestion anyway.

You could wrap that list of const assignments up into some sort of
class method `enum` that creates the consts from a list of names (and
maybe a starting offset).

Yes, that's the obvious consequence to draw from this approach.

what you're asking for wrt fiddle treating enums like types rather
than named numbers is outside the scope of what fiddle is for. If you
want to do extra arg checking, that's on you. That's not the job of
ruby, fiddle, _or_ C.

The expectation came from using ruby-ffi, which does have special
treatment for enums[1], and as ruby-ffi and fiddle serve the same
purpose after all, it did not occur to me that handling of enums is out
of scope for fiddle.

Greetings
Marvin

[1]: Enums · ffi/ffi Wiki · GitHub

···

On Wed, Jan 11, 2017 at 03:53:06AM -0800, Ryan Davis wrote:

--
Blog: http://www.guelkerdev.de
PGP/GPG ID: F1D8799FBCC8BC4F