Joshh44

Line Finder by JoshhT

Oct 14th, 2012
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. --[[
  2. This code is written soley, and completely by JoshhT.
  3. Skype : JoshhT44
  4. Please do not steal, distribute, or plagiarise my work.
  5. If this code has helped you, feel free to thank me :)
  6. Whether it be a +1 on the post, or adding me on skype to say thanks.
  7. ]]--
  8.  
  9.  
  10. local args = {...}
  11.  
  12. function cleanup()
  13.   local a = args[1]
  14.   local b = ""
  15.   if string.sub(a, 1, 1) == "\"" then
  16.     b = string.sub(a, 2, -1)
  17.   else
  18.     b = a
  19.   end
  20.   a = string.reverse(b)
  21.   if string.sub(a, 1, 1) == "\"" then
  22.     b = string.sub(a, 2, -1)
  23.     b = string.reverse(b)
  24.   end
  25.   return b
  26. end
  27.  
  28. local fileLoc = cleanup()
  29. local lineNum = tonumber(args[2])
  30.  
  31. function program()
  32.   local file = fs.open(fileLoc, "r")
  33.   local list = {}
  34.   local line = file.readLine()
  35.  
  36.   repeat
  37.   table.insert(list, line)
  38.   line = file.readLine()
  39.   until line == nil
  40.  
  41.   file.close()
  42.   print("Line " .. lineNum .. ": " .. list[lineNum])
  43. end
  44.  
  45. if #args == 2 then
  46.   if fs.exists(fileLoc) then
  47.     program()
  48.   else
  49.     print("Invalid file location.")
  50.   end
  51. elseif args[1] == "help" then
  52.   print [[This program was written to help people
  53. Find an exact line in their program.
  54. Simply type in the program location,
  55. With or without the quotation marks, it works either way :)
  56. Then type the line you wish to retrieve. Example:
  57. lineFinder "/disk/mining/branch" 34
  58. Would print line 34 within the file specified.
  59. Any errors should be directed here,
  60. http://www.computercraft.info/forums2/index.php?/topic/5032-line-finder-by-joshht/
  61.  
  62. Thanks for using my program :)
  63. JoshhT.]]
  64. else
  65.   print("Please enter the file destination\nAnd line number only.")
  66. end
Advertisement
Add Comment
Please, Sign In to add comment