Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

limit

By: a guest on Jul 5th, 2013  |  syntax: Lua  |  size: 1.25 KB  |  views: 256  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. keys = {"esc", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "back", "tab", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", "enter", "ctrl", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", nil, "shift", nil, "z", "x", "c", "v", "b", "n", "m", ",", ".", "/", nil, "*", nil, " "}
  2. string = ""
  3.  
  4. function limitread(num, hide)
  5.   string = ""
  6.   for i=0, num, 1 do
  7.     event, key = os.pullEvent("key")
  8.     if keys[key] ~= nil and num ~= nil then
  9.       if keys[key] == "enter" then
  10.         return string
  11.      elseif keys[key] == "back" then
  12.         --oldString = string
  13.        -- string = string.sub(string, #string-1)
  14.        -- m, n = term.getCursorPos()
  15.        -- x, y = term.getCursorPos()
  16.        -- x = x - #string
  17.        -- for f=0, #oldString, 1 do
  18.          -- write(" ")
  19.       --  end
  20.        -- for b=0, #string, 1 do
  21.         --  if hide ~= nil then
  22.          --   write(string)
  23.          -- else
  24.            -- for v=0, #string, 1 do
  25.            --   write(hide)
  26.            -- end
  27.          -- end
  28.        --end
  29.       --  ]]
  30.       else
  31.         if hide == nil then
  32.           write(keys[key])
  33.         else
  34.           write(hide)
  35.         end
  36.         string = string..keys[key]
  37.       end
  38.     end
  39.   end
  40.   return string
  41. end