123456789_123456789_123456789_123456789_123456789_

Class: Fiddle::Function

Relationships & Source Files
Inherits: Object
Defined in: ext/fiddle/function.c,
ext/fiddle/lib/fiddle/function.rb

Overview

Description

A representation of a C function

Examples

'strcpy'

@libc = Fiddle.dlopen "/lib/libc.so.6"
   #=> #<Fiddle::Handle:0x00000001d7a8d8>
f = Fiddle::Function.new(
  @libc['strcpy'],
  [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP],
  Fiddle::TYPE_VOIDP)
   #=> #<Fiddle::Function:0x00000001d8ee00>
buff = "000"
   #=> "000"
str = f.call(buff, "123")
   #=> #<Fiddle::Pointer:0x00000001d0c380 ptr=0x000000018a21b8 size=0 free=0x00000000000000>
str.to_s
#=> "123"

ABI check

@libc = Fiddle.dlopen "/lib/libc.so.6"
   #=> #<Fiddle::Handle:0x00000001d7a8d8>
f = Fiddle::Function.new(@libc['strcpy'], [TYPE_VOIDP, TYPE_VOIDP], TYPE_VOIDP)
   #=> #<Fiddle::Function:0x00000001d8ee00>
f.abi == Fiddle::Function::DEFAULT
   #=> true

Constant Summary

Class Method Summary

Instance Attribute Summary

  • #abi readonly

    The ABI of the Function.

  • #name readonly

    The name of this function.

  • #ptr readonly

    The address of this function.

Instance Method Summary

Constructor Details

.new(ptr, args, ret_type, abi = DEFAULT)

Constructs a Function object.

  • #ptr is a referenced function, of a Handle

  • args is an Array of arguments, passed to the #ptr function

  • ret_type is the return type of the function

  • #abi is the ABI of the function

Instance Attribute Details

#abi (readonly)

The ABI of the Function.

[ GitHub ]

  
# File 'ext/fiddle/lib/fiddle/function.rb', line 4

attr_reader :abi

#name (readonly)

The name of this function

[ GitHub ]

  
# File 'ext/fiddle/lib/fiddle/function.rb', line 10

attr_reader :name

#ptr (readonly)

The address of this function

[ GitHub ]

  
# File 'ext/fiddle/lib/fiddle/function.rb', line 7

attr_reader :ptr

Instance Method Details

#call(argv[], self)

Calls the constructed Function, with args

For an example see Function

#to_i

The integer memory location of this function

[ GitHub ]

  
# File 'ext/fiddle/lib/fiddle/function.rb', line 13

def to_i
  ptr.to_i
end