NielsUtrecht

coroutine

Sep 10th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.66 KB | None | 0 0
  1. local s = ""
  2. os.startTimer(2)
  3.  
  4. local function command(com)
  5.     print("'"..com.."'")
  6.     if(com == ":quit") then
  7.         error()
  8.     end
  9. end
  10.  
  11. local function clearInput()
  12.     s = ""
  13.     term.setCursorPos(1,5)
  14.     term.clearLine()
  15.     term.write(">")
  16. end
  17.  
  18. term.clear()
  19. term.setCursorBlink(true)
  20. clearInput()
  21.  
  22. while true do
  23.     event, param1, param2, param3 = os.pullEvent()
  24.  
  25.     if(event == "char") then
  26.         s = s .. param1
  27.         term.write(param1)
  28.     elseif(event == "key") then
  29.         if(param1 == keys.enter) then
  30.             clearInput()
  31.             command(s)
  32.         end
  33.     elseif(event == "timer") then
  34.         os.startTimer(2)
  35.     else
  36.         print(event .. ":" .. param1 .. "," .. param2 .. "," ..param3)
  37.     end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment