Module: Yadriggy::C::CFI
- Defined in:
- lib/yadriggy/c/ffi.rb
Overview
C Function Interface
Class Method Summary collapse
-
.c_type(type) ⇒ Symbol
Type name for FFI.
-
.c_type_name(type) ⇒ String
Type name in C.
- .param_types(method_type) ⇒ Object
- .return_type(method_type) ⇒ Object
Class Method Details
.c_type(type) ⇒ Symbol
Returns type name for FFI.
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/yadriggy/c/ffi.rb', line 282 def self.c_type(type) type = type.supertype if InstanceType.role(type) if type == RubyClass::Integer || type == Integer :int32 elsif type == RubyClass::Float || type == Float :double elsif type == CType::Void :void elsif type == RubyClass::String || type == String :string elsif type == CType::Float32Type || type == CType::Float32 :float else raise "bad type #{type}" if ArrayType.role(type).nil? :pointer end end |
.c_type_name(type) ⇒ String
Returns type name in C.
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/yadriggy/c/ffi.rb', line 261 def self.c_type_name(type) type = type.supertype if InstanceType.role(type) if type == RubyClass::Integer || type == Integer 'int32_t' elsif type == RubyClass::Float || type == Float 'double' elsif type == CType::Void 'void' elsif type == RubyClass::String || type == String 'char*' elsif type == CType::Float32Type || type == CType::Float32 'float' else at = ArrayType.role(type) raise "bad type #{type.inspect}" if at.nil? "#{c_type_name(at.element_type)}*" end end |
.param_types(method_type) ⇒ Object
249 250 251 252 253 |
# File 'lib/yadriggy/c/ffi.rb', line 249 def self.param_types(method_type) method_type.params.map do |t| c_type(t) end end |
.return_type(method_type) ⇒ Object
255 256 257 |
# File 'lib/yadriggy/c/ffi.rb', line 255 def self.return_type(method_type) c_type(method_type.result_type) end |