Advertisement
Dima99

tabler

Aug 3rd, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 KB | None | 0 0
  1. --options
  2. --naming modes 1=using addition, 2=naming as default
  3.  
  4. textName = "table"
  5. addition = "T"
  6. namingMode = 1
  7.  
  8. --
  9.  
  10. version = "1.1.2"
  11. arg = { ... }
  12. fullName = shell.getRunningProgram()
  13. usedName = textName
  14. path = shell.dir()
  15. name = string.gsub(fullName, path.."/", "")
  16. array = {}
  17.  
  18. if #arg < 1 then
  19.  print("Usage: "..name.." <path>")
  20.  return
  21.  elseif #arg > 1 then
  22.  print("Usage: "..name.." <path>")
  23. end
  24.  
  25. if not fs.exists(tostring(arg[1])) then
  26.  print("This file doesn't exists")
  27.  return
  28. end
  29.  
  30. --
  31.  
  32. function read(path)
  33.  f = fs.open(path, "r")
  34.  local i = 1
  35.  local temp
  36.  while true do
  37.   temp = f.readLine()
  38.   if not temp then break end
  39.   if #temp == 0 then temp = " " end
  40.   array[i] = temp
  41.   i = i + 1  
  42.  end
  43.  f.close()
  44. end
  45.  
  46. function write()
  47.  if namingMode == 2 then
  48.   h = fs.open(path.."/"..usedName, "w")
  49.   elseif namingMode == 1 then
  50.   h = fs.open(path.."/"..arg[1]..addition, "w")
  51.  end
  52.  h.write(arg[1].." = {'"..array[1])
  53.  for i = 2, #array do
  54.   h.write("', '"..array[i])
  55.  end
  56.  h.write("'}")
  57.  h.close()
  58. end
  59.  
  60. function selName()
  61. relay = true
  62.  local a = 1
  63.  while relay do
  64.   if fs.exists(path..usedName) then
  65.    usedName = textName..tostring(a)
  66.    a = a + 1
  67.    else relay = false
  68.   end
  69.  end
  70. end
  71.  
  72. --
  73.  
  74. read(path.."/"..arg[1])
  75. selName()
  76. write(array)
  77. f.close()
  78. h.close()
  79. print("Ready!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement