Guest User

tapedrive

a guest
Mar 23rd, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.75 KB | None | 0 0
  1. local component = require "component"
  2.  
  3. local tape = component.tape_drive
  4.  
  5. local tArgs = {...}
  6.  
  7. -------------------------------------------
  8.  
  9. local function rezero()
  10.  tape.seek(0-tape.getSize())
  11. end
  12.  
  13. local function write(file)
  14.  rezero()
  15.  local fobj = io.open(file,"r")
  16.  text = fobj:read("*a")
  17.  fobj:close()
  18.  print(text:len())
  19.  local byte = text:byte(1)
  20.  local n = 1
  21.  repeat
  22.   tape.write(byte)
  23.   n = n + 1
  24.   byte = text:byte(n)
  25.  until byte == nil
  26. end
  27.  
  28. local function read(amount)
  29.  rezero()
  30.  local outstr = ""
  31.  repeat
  32.   outstr = outstr..string.char(tape.read())
  33.   amount = amount - 1
  34.  until amount == 0
  35.  local fobj = io.open(tArgs[3],"w")
  36.  fobj:write(outstr)
  37.  fobj:close()
  38. end
  39.  
  40. if tArgs[1] == "read" then
  41.  read(tArgs[2])
  42. elseif tArgs[1] == "write" then
  43.  write(tArgs[2])
  44. end
Advertisement
Add Comment
Please, Sign In to add comment