Suppose I define an enum under cffi:
from cffi import FFI
ffi = FFI()
ffi.cdef('typedef enum {RANDOM, IMMEDIATE, SEARCH} strategy;')
Now this can be easily accessed when calling cdef
again. But how would I then like to access this enum in python, without re-declaring it? Can't find any mentions in the docs.
If you have wrapped over a library you can use the same above as following :
Following @falsetru's answer,
ffi.dlopen('c')
doesn't work anymore for Windows 7 and Python 3.7, but I discovered today that we can use any library instead of'c'
and it still works. The recommended one at https://bugs.python.org/issue23606 is to useucrtbase.dll
, so we can do:Another more complicated way for enums is to use
self.typeof('strategy').relements['RANDOM']
, but this does not work for#define
s, so the above way is better.Use
ffi.dlopen
, and access the enum value by qualifying using the return value of theffi.dlopen
: