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
-
DEFAULT =
Default ABI
INT2NUM(FFI_DEFAULT_ABI)
-
STDCALL =
FFI implementation of WIN32 stdcall convention
INT2NUM(FFI_STDCALL)
Class Method Summary
-
.new(ptr, args, ret_type, abi = DEFAULT)
constructor
Constructs a
Function
object.
Instance Attribute Summary
Instance Method Summary
-
#call(argv[], self)
Calls the constructed
Function
, withargs
-
#to_i
The integer memory location of this function.
Constructor Details
.new(ptr, args, ret_type, abi = DEFAULT)
Instance Attribute Details
#abi (readonly)
The ABI of the Function
.
# File 'ext/fiddle/lib/fiddle/function.rb', line 4
attr_reader :abi
#name (readonly)
The name of this function
# File 'ext/fiddle/lib/fiddle/function.rb', line 10
attr_reader :name
#ptr (readonly)
The address of this function
# 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
# File 'ext/fiddle/lib/fiddle/function.rb', line 13
def to_i ptr.to_i end