Advertisement
Guest User

CompileStep1.lua

a guest
Apr 7th, 2020
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.74 KB | None | 0 0
  1. local term = require("term")
  2. local code = {}
  3. local cntr = 1
  4. local serial = require("serialization")
  5. local fs = require("filesystem")
  6.  
  7.  
  8. term.clear()
  9. term.write("Filename?")
  10. term.setCursor(1,2)
  11. local fileName = io.read()
  12. term.setCursor(1,3)
  13. term.write("Extension?")
  14. term.setCursor(1,4)
  15. local extension = io.read()
  16. local inputFileName = fileName .. extension
  17. local outputFile = fileName .. ".serial"
  18. local file = assert(fs.open(inputFileName, "r"))
  19. local size = fs.size(inputFileName)
  20. inputFile = file:read(size)
  21. term.setCursor(1,5)
  22. term.write("Converting file")
  23. term.setCursor(1,6)
  24. local token = ""
  25.  
  26. for token in string.gmatch(inputFile, "[^%s]+") do
  27.   code[cntr] = token
  28.   cntr = cntr + 1
  29. end
  30. output = io.open(outputFile, "w")
  31. output:write(serial.serialize(code))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement