Class: RCGTK::FunctionType

Inherits:
Type
  • Object
show all
Defined in:
lib/rcgtk/type.rb

Overview

A type representing the return an argument types for a function.

Instance Attribute Summary

Attributes included from BindingClass

#ptr

Instance Method Summary collapse

Methods inherited from Type

#allignment, #context, #dump, from_ptr, #hash, #kind, #size, #to_s

Methods included from BindingClass

#==

Constructor Details

#initialize(overloaded, arg_types = nil, varargs = false) ⇒ FunctionType

Create a new function type from a pointer or description of the return type and argument types.

Parameters:

  • overloaded (FFI::Pointer, Type)

    Pointer to existing function type or the return type.

  • arg_types (Array<Type>) (defaults to: nil)

    Types of the function’s arguments.

  • varargs (Boolean) (defaults to: false)

    Weather or not this function has varargs.



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/rcgtk/type.rb', line 362

def initialize(overloaded, arg_types = nil, varargs = false)
	@ptr =
	case overloaded
	when FFI::Pointer
		overloaded
	else
		@return_type	= check_cg_type(overloaded, Type, 'return_type')
		@arg_types	= check_cg_array_type(arg_types, Type, 'arg_types').freeze

		arg_types_ptr = FFI::MemoryPointer.new(:pointer, @arg_types.length)
		arg_types_ptr.write_array_of_pointer(@arg_types)

		Bindings.function_type(@return_type, arg_types_ptr, @arg_types.length, varargs.to_i)
	end
end

Instance Method Details

#argument_typesArray<Type> Also known as: arg_types

Returns Types of this function type’s arguments.

Returns:

  • (Array<Type>)

    Types of this function type’s arguments.



379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/rcgtk/type.rb', line 379

def argument_types
	@arg_types ||=
	begin
		num_elements = Bindings.count_param_types(@ptr)

		ret_ptr = FFI::MemoryPointer.new(:pointer)
		Bindings.get_param_types(@ptr, ret_ptr)

		types_ptr = ret_ptr.get_pointer(0)

		types_ptr.get_array_of_pointer(0, num_elements).map { |ptr| Type.from_ptr(ptr) }
	end
end

#return_typeType

Returns The return type of this function type.

Returns:

  • (Type)

    The return type of this function type.



395
396
397
# File 'lib/rcgtk/type.rb', line 395

def return_type
	@return_type ||= Type.from_ptr(Bindings.get_return_type(@ptr))
end