Class: WASI::CIOVec

Inherits:
Object show all
Defined in:
lib/rlang/lib/wasi.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n) ⇒ CIOVec

Returns a new instance of CIOVec.



26
27
28
29
30
31
32
33
# File 'lib/rlang/lib/wasi.rb', line 26

def initialize(n)
  result :none
  # a ciov is list of n (address to buffer, length of buffer)
  @n = n
  @index = 0
  @max_index = 2 * @n
  @ciovs = Array32.new(2*n)
end

Instance Attribute Details

#ciovsObject (readonly)

Returns the value of attribute ciovs.



23
24
25
# File 'lib/rlang/lib/wasi.rb', line 23

def ciovs
  @ciovs
end

Instance Method Details

#<<(string) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/rlang/lib/wasi.rb', line 35

def << (string)
  arg string: :String
  result :CIOVec
  raise "CIOVec full !" if @index >= @max_index
  @ciovs[@index] = string.ptr
  @ciovs[@index+1] = string.length
  @index += 2
  self
end

#freeObject



45
46
47
48
49
# File 'lib/rlang/lib/wasi.rb', line 45

def free
  result :none
  @ciovs.free
  Object.free(self)
end