在 Enums 的 ffi 文档(https://github.com/ffi/ffi/wiki/Enums)中提到,当您创建 ffi 时,例如:
# Example using enums
module Week
extend FFI::Library
ffi_lib "week"
enum :day, [:sunday, 1,
:monday,
:tuesday,
:wednesday,
:thursday,
:friday,
:saturday ]
attach_function :is_work_day, [ :day ], :int
end
# How you would call the function:
Week.is_work_day( :monday )
# This is also allowed, in case you need to use integers:
Week.is_work_day( 2 )
问题是:当您发送“2”时,它会查看 :day 枚举并找到第二个条目的值,还是将实际的“2”值发送到您的函数?