Class: DL::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/dl/stack.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types) ⇒ Stack

Returns a new instance of Stack.



9
10
11
# File 'lib/dl/stack.rb', line 9

def initialize(types)
  parse_types(types)
end

Class Method Details

.[](*types) ⇒ Object



5
6
7
# File 'lib/dl/stack.rb', line 5

def self.[](*types)
  new(types)
end

Instance Method Details

#pack(ary) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/dl/stack.rb', line 21

def pack(ary)
  case SIZEOF_VOIDP
  when SIZEOF_LONG
    ary.pack(@template).unpack('l!*')
  when SIZEOF_LONG_LONG
    ary.pack(@template).unpack('q*')
  else
    raise(RuntimeError, "sizeof(void*)?")
  end
end

#sizeObject



13
14
15
# File 'lib/dl/stack.rb', line 13

def size()
  @size
end

#typesObject



17
18
19
# File 'lib/dl/stack.rb', line 17

def types()
  @types
end

#unpack(ary) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/dl/stack.rb', line 32

def unpack(ary)
  case SIZEOF_VOIDP
  when SIZEOF_LONG
    ary.pack('l!*').unpack(@template)
  when SIZEOF_LONG_LONG
    ary.pack('q*').unpack(@template)
  else
    raise(RuntimeError, "sizeof(void*)?")
  end
end