Kamioda

Untitled

Jul 24th, 2021 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. function split(str, ts)
  2. -- 引数がないときは空tableを返す
  3. if ts == nil then return {} end
  4. local t = {} ;
  5. i=1
  6. for s in string.gmatch(str, "([^"..ts.."]+)") do
  7. t[i] = s
  8. i = i + 1
  9. end
  10. return t
  11. end
  12.  
  13. local function write1()
  14. local f = io.open("last.dat", "w")
  15. f:write("1,2,3,N")
  16. f:close()
  17. end
  18.  
  19. local function write2()
  20. local f = io.open("last.dat", "w")
  21. f:write("3,2,1,N")
  22. f:close()
  23. end
  24.  
  25. local function read()
  26. local f = io.open("last.dat", "r")
  27. for line in f:lines() do
  28. local strs = split(line, ",")
  29. for i = 1, #strs do
  30. print(strs[i])
  31. end
  32. end
  33. f:close()
  34. end
  35.  
  36. local quitFlag = false
  37.  
  38. local function quitProcess()
  39. local event, param1 = os.pullEvent()
  40. if param1 == "q" then
  41. write2()
  42. quitFlag = true
  43. end
  44. end
  45.  
  46. while not quitFlag do
  47. parallel.waitForAny(quitProcess)
  48. read()
  49. os.sleep(0.05)
  50. end
  51.  
Add Comment
Please, Sign In to add comment