lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 1/15/2011 2:54 PM, Mike Pall wrote:
> Well, I don't want to copy _all_ of the joys of C++ in Lua. :-)
> So LuaJIT simply allows all of these:
>
>   ffi.cdef[[
>   typedef enum { RED, GREEN, BLUE } PrimaryColor;
>   int bar(PrimaryColor x);
>   ]]
>
>   ffi.C.bar(2)
>   ffi.C.bar(ffi.C.BLUE)
>   ffi.C.bar("BLUE") -- Strings are (type-safe!) converted to enums.

Are enum function return types supported?

I get "attempt to compare 'enum 95' with 'double'" error message when i
try something like this:

  ffi.cdef[[PrimaryColor foo();]]
  if foo() == ffi.C.BLUE then ...

I would like to avoid using tonumber():

  if tonumber(foo()) == ffi.C.BLUE then ...

Thanks.