Class: Fiddle::Pointer
| Relationships & Source Files | |
| Extension / Inclusion / Inheritance Descendants | |
|
Subclasses:
|
|
| Inherits: | Object |
| Defined in: | ext/fiddle/pointer.c |
Overview
Pointer is a class to handle C pointers
Class Method Summary
-
Fiddle::Pointer ⇒ cptr
(also: .to_ptr)
Get the underlying pointer for ruby object
valand return it as aPointerobject. -
.new(address) ⇒ fiddle_cptr
constructor
Create a new pointer to
addresswith an optional #size andfreefunc. -
.to_ptr(val) ⇒ cptr
Alias for .[].
Instance Attribute Summary
-
#free ⇒ Fiddle::Function
rw
Get the free function for this pointer.
-
#free=(function)
rw
Set the free function for this pointer to
functionin the given Function. -
#size
rw
Get the size of this pointer.
-
#size=(size)
rw
Set the size of this pointer to #size
-
#null? ⇒ Boolean
readonly
Returns
trueif this is a null pointer.
Instance Method Summary
-
#+(n) ⇒ new cptr
Returns a new pointer instance that has been advanced
nbytes. -
#+@
(also: #ptr)
Returns a new
Pointerinstance that is a dereferenced pointer for this pointer. -
#-(n) ⇒ new cptr
Returns a new pointer instance that has been moved back
nbytes. -
#-@
(also: #ref)
Returns a new
Pointerinstance that is a reference pointer for this pointer. -
#<=>(other) ⇒ 1, ...
Returns -1 if less than, 0 if equal to, 1 if greater than
other. -
#==(other) ⇒ Boolean
(also: #eql?)
Returns true if
otherwraps the same pointer, otherwise returns false. -
#[](index) ⇒ Integer
Returns integer stored at index.
-
#[]=(index, int) ⇒ Integer
Set the value at
indextoint. -
#eql?(other) ⇒ Boolean
Alias for #==.
-
#inspect
Returns a string formatted with an easily readable representation of the internal state of the pointer.
-
#ptr
Alias for #+@.
-
#ref
Alias for #-@.
-
#to_i ⇒ Integer
(also: #to_int)
Returns the integer memory location of this pointer.
-
#to_int ⇒ Integer
Alias for #to_i.
-
#to_s ⇒ String
Returns the pointer contents as a string.
-
#to_str ⇒ String
Returns the pointer contents as a string.
-
#to_value ⇒ ?
Cast this pointer to a ruby object.
Constructor Details
.new(address) ⇒ fiddle_cptr
.new(address, size) ⇒ fiddle_cptr
.new(address, size, freefunc) ⇒ fiddle_cptr
fiddle_cptr
.new(address, size) ⇒ fiddle_cptr
.new(address, size, freefunc) ⇒ fiddle_cptr
Create a new pointer to address with an optional #size and freefunc.
freefunc will be called when the instance is garbage collected.
Class Method Details
Fiddle::Pointer ⇒ cptr
.to_ptr(val) ⇒ cptr
Also known as: .to_ptr
cptr
.to_ptr(val) ⇒ cptr
Get the underlying pointer for ruby object val and return it as a Pointer object.
Fiddle::Pointer ⇒ cptr
.to_ptr(val) ⇒ cptr
cptr
.to_ptr(val) ⇒ cptr
Alias for .[].
Instance Attribute Details
#free ⇒ Fiddle::Function (rw)
#free=(function) (rw)
Set the free function for this pointer to function in the given Function.
#null? ⇒ Boolean (readonly)
Returns true if this is a null pointer.
#size (rw)
Get the size of this pointer.
#size=(size) (rw)
Set the size of this pointer to #size
Instance Method Details
#+(n) ⇒ new cptr
Returns a new pointer instance that has been advanced n bytes.
#+@ Also known as: #ptr
Returns a new Pointer instance that is a dereferenced pointer for this pointer.
Analogous to the star operator in C.
#-(n) ⇒ new cptr
Returns a new pointer instance that has been moved back n bytes.
#-@ Also known as: #ref
Returns a new Pointer instance that is a reference pointer for this pointer.
Analogous to the ampersand operator in C.
#<=>(other) ⇒ 1, ...
Returns -1 if less than, 0 if equal to, 1 if greater than other.
Returns nil if #ptr cannot be compared to other.
#==(other) ⇒ Boolean
#eql?(other) ⇒ Boolean
Also known as: #eql?
Boolean
#eql?(other) ⇒ Boolean
Returns true if other wraps the same pointer, otherwise returns false.
#[](index) ⇒ Integer
#[](start, length) ⇒ String
Integer
#[](start, length) ⇒ String
Returns integer stored at index.
If start and length are given, a string containing the bytes from start of length will be returned.
#[]=(index, int) ⇒ Integer
#[]=(start, length, string or cptr or addr) ⇒ String, ...
Integer
#[]=(start, length, string or cptr or addr) ⇒ String, ...
Set the value at index to int.
Or, set the memory at start until length with the contents of string, the memory from dl_cptr, or the memory pointed at by the memory address addr.
#==(other) ⇒ Boolean
#eql?(other) ⇒ Boolean
Boolean
#eql?(other) ⇒ Boolean
Alias for #==.
#inspect
Returns a string formatted with an easily readable representation of the internal state of the pointer.
#+@
#ptr
Alias for #+@.
#-@
#ref
Alias for #-@.
#to_i ⇒ Integer Also known as: #to_int
Returns the integer memory location of this pointer.
#to_i ⇒ Integer
#to_int ⇒ Integer
Integer
#to_int ⇒ Integer
Alias for #to_i.
#to_s ⇒ String
#to_s(len) ⇒ String
String
#to_s(len) ⇒ String
Returns the pointer contents as a string.
When called with no arguments, this method will return the contents until the first NULL byte.
When called with len, a string of len bytes will be returned.
See to_str
#to_str ⇒ String
#to_str(len) ⇒ String
String
#to_str(len) ⇒ String
Returns the pointer contents as a string.
When called with no arguments, this method will return the contents with the length of this pointer's #size.
When called with len, a string of len bytes will be returned.
See to_s
#to_value ⇒ ?
Cast this pointer to a ruby object.