Class: IO
Constant Summary collapse
- @@num_bytes_written =
0
- @@num_bytes_read =
0
Instance Attribute Summary collapse
-
#fd ⇒ Object
Returns the value of attribute fd.
Instance Method Summary collapse
-
#initialize(fd) ⇒ IO
constructor
A new instance of IO.
- #print(stg) ⇒ Object
- #puts(stg) ⇒ Object
- #read ⇒ Object
- #write(stg) ⇒ Object
Constructor Details
#initialize(fd) ⇒ IO
Returns a new instance of IO.
15 16 17 |
# File 'lib/rlang/lib/io.rb', line 15 def initialize(fd) @fd = fd end |
Instance Attribute Details
#fd ⇒ Object
Returns the value of attribute fd.
10 11 12 |
# File 'lib/rlang/lib/io.rb', line 10 def fd @fd end |
Instance Method Details
#print(stg) ⇒ Object
28 29 30 |
# File 'lib/rlang/lib/io.rb', line 28 def print(stg) self.write(stg) end |
#puts(stg) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/rlang/lib/io.rb', line 32 def puts(stg) arg stg: :String result :none ciovec = WASI::CIOVec.new(2) ciovec << stg ciovec << "\n" errno = WASI.fd_write(@fd, ciovec.ciovs.ptr, 2, @@num_bytes_written.addr) ciovec.free end |
#read ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rlang/lib/io.rb', line 42 def read result :String local stg: :String iovec = WASI::IOVec.new(1) errno = WASI.fd_read(@fd, iovec.iovs.ptr, 1, @@num_bytes_read.addr) # -1 below because of \0 terminated string stg = String.new(iovec.iovs[0], @@num_bytes_read-1) # Nullify the iovs entry used by the String object so it is not freed iovec.iovs[0] = 0 iovec.free stg end |