Advertisement
mathiaas

file

Dec 19th, 2019 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.68 KB | None | 0 0
  1. local _input = {...}
  2.  
  3. if not fs.exists("/.db") then
  4.     io.open("/.db","w")
  5. end
  6.  
  7. file = fs.open("/.db", "r")
  8.  
  9. local rLines = {}
  10. local sLine = file.readLine()
  11. while sLine do
  12.     table.insert(rLines, sLine)
  13.     sLine = file.readLine()
  14. end
  15. file.close()
  16.  
  17. match = false
  18. for k,v in pairs(rLines) do
  19.     if (string.match(rLines[k],_input[1])) then
  20.         rLines[k] = rLines[k]:gsub(_input[1]..":","")
  21.         rLines[k] = _input[1]..":"..(rLines[k] + _input[2])
  22.         match = true
  23.     end
  24. end
  25.  
  26. if not match then
  27.     table.insert(rLines, _input[1]..":".._input[2])
  28. end
  29.  
  30. file = fs.open("/.db", "w")
  31. for _,line in pairs(rLines) do
  32.     file.writeLine(line)
  33. end
  34. file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement