class RLTK::CG::FunctionType

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

Attributes

arg_types[R]

@return [Array<Type>] Types of this function type’s arguments.

Public Class Methods

new(overloaded, arg_types = nil, varargs = false) click to toggle source

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

@param [FFI::Pointer, Type] overloaded Pointer to existing function type or the return type. @param [Array<Type>] arg_types Types of the function’s arguments. @param [Boolean] varargs Weather or not this function has varargs.

# File lib/rltk/cg/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

Public Instance Methods

argument_types() click to toggle source

@return [Array<Type>] Types of this function type’s arguments.

# File lib/rltk/cg/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
Also aliased as: arg_types
return_type() click to toggle source

@return [Type] The return type of this function type.

# File lib/rltk/cg/type.rb, line 395
def return_type
        @return_type ||= Type.from_ptr(Bindings.get_return_type(@ptr))
end