Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. mon = wrap("top")
  2. monh = 2
  3. monl = 4
  4.  
  5. monh = monh*5
  6. monl = monl*7
  7.  
  8. lines = {}
  9.  
  10.  
  11. function updatemonitor()
  12.     mon.clear()
  13.     for i, v in ipairs(lines) do
  14.         mon.setCursorPos(i,0)
  15.         mon.write(v)
  16.     end
  17. end
  18.  
  19. function fixtable()
  20.     local tmptable = {}
  21.     for i, v in ipairs(lines) do
  22.         table.insert(tmptable, #tmptable, v)
  23.     end
  24.     lines = tmptable
  25. end
  26.  
  27. function chkline(line)
  28.     if not #lines+1 > monh then
  29.         if not string.len(line) > monl then
  30.             return true
  31.         else
  32.             return false, "Entry too long, Max of "..monl.." characters."
  33.         end
  34.     else
  35.         return false, "No Space. Delete an Entry."
  36.     end
  37. end
  38.  
  39. function add(line)
  40.     local chkl, f = chkline(line)
  41.     if chkl == true then
  42.         table.insert(lines, #lines+1, line)
  43.         updatemonitor()
  44.     else
  45.         print(f)
  46.     end
  47. end
  48.  
  49. function matchline(line)
  50.     for i, v in ipairs(lines) do
  51.         if v:lower() == line:lower() then
  52.             return i
  53.         end
  54.     end
  55. end
  56.  
  57. function rm(inp, cl)
  58.     if type(inp) == "number" then
  59.         table.remove(lines, inp)
  60.     elseif type(inp) == "string" then
  61.         local ml = matchline(inp)
  62.         if ml then
  63.             table.remove(lines, ml)
  64.         else
  65.             print("Invalid line")
  66.         end
  67.     else
  68.         print("Line not specifified")
  69.     end
  70.     fixtable()
  71.     if not cl then
  72.         updatemonitor()
  73.     end
  74. end
  75.  
  76. function clear()
  77.     for i, v in ipairs(lines) do
  78.         rm(i, true)
  79.     end
  80.     updatemonitor()
  81. end
  82.  
  83.  
  84. while true do
  85.     input = read()
  86.     input = string.lower(input)
  87.     if input == "clear" then
  88.         clear()
  89.     elseif string.sub(input, 1, 3) = "rm " then
  90.         rm(string.sub(input, 4)
  91.     elseif string.sub(input, 1, 4) == "add " then
  92.         add(string.sub(input, 5)
  93.     else
  94.         print("Invalid Command")
  95.     end
  96.  
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement