Class: CGLM::Base
- Inherits:
-
Object
- Object
- CGLM::Base
- Defined in:
- lib/cglm/base.rb,
ext/cglm/rb_cglm.c
Direct Known Subclasses
Instance Attribute Summary collapse
-
#addr ⇒ Object
(also: #to_ptr)
Returns the value of attribute addr.
Instance Method Summary collapse
- #copy_to(other) ⇒ Object
- #dup(other = nil) ⇒ Object
-
#initialize(addr: CGLM.alloc(self.class).tap { |ptr| # Init malloc'd values to 0; there is a PR to fiddle for this, then we # can delete this code. https://github.com/ruby/fiddle/pull/14 ptr[0, self.class.size] = "\x00".b * self.class.size }) ⇒ Base
constructor
A new instance of Base.
- #initialize_dup(other) ⇒ Object
Constructor Details
#initialize(addr: CGLM.alloc(self.class).tap { |ptr| # Init malloc'd values to 0; there is a PR to fiddle for this, then we # can delete this code. https://github.com/ruby/fiddle/pull/14 ptr[0, self.class.size] = "\x00".b * self.class.size }) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cglm/base.rb', line 8 def initialize(addr: CGLM.alloc(self.class).tap { |ptr| # Init malloc'd values to 0; there is a PR to fiddle for this, then we # can delete this code. https://github.com/ruby/fiddle/pull/14 ptr[0, self.class.size] = "\x00".b * self.class.size }) # Even if addr is present, but points to NULL, this is a problem that # will lead to segfaults. If not present, `nil.to_i == 0`. raise ArgumentError, 'BUG: object initialized without a backing store?' if addr.to_i == 0 self.addr = addr end |
Instance Attribute Details
#addr ⇒ Object Also known as: to_ptr
Returns the value of attribute addr.
5 6 7 |
# File 'lib/cglm/base.rb', line 5 def addr @addr end |
Instance Method Details
#copy_to(other) ⇒ Object
19 20 21 22 23 |
# File 'lib/cglm/base.rb', line 19 def copy_to(other) size = addr.size > other.addr.size ? other.addr.size : addr.size other.addr[0, size] = addr other end |
#dup(other = nil) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/cglm/base.rb', line 25 def dup(other = nil) if other copy_to other else super() end end |