Advertisement
Guest User

conf.so

a guest
Aug 23rd, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.81 KB | None | 0 0
  1. --[[function readConf(file,key)
  2.     local file=fs.open(file,"r")
  3.     while true do
  4.         sText=file.readLine()
  5.         local start=string.find(sText,"=")
  6.         if string.sub(sText,1,start)==key then
  7.             break
  8.         end
  9.     end
  10.     file.close()
  11.     local start=string.find(sText,"=")
  12.     return string.sub(sText,start+1,#sText)
  13. end]]
  14. function read(sFile,key)
  15.     if not fs.exists(sFile..".ltx") then error("No such file") end
  16.     local file = fs.open(sFile..".ltx","r")
  17.     while true do
  18.         local line = file.readLine()
  19.         if line ~= nil then
  20.             local key, value = string.match(line,"(.*)=(.*)")
  21.             if value ~= nil and key == key then
  22.                 file.close()
  23.                 return value
  24.             end
  25.         else
  26.             file.close()
  27.             break
  28.         end
  29.     end
  30. end
  31. function write(sfile,key,value)
  32.     local file=fs.open(sfile..".ltx","a")
  33.     file.writeLine(key.."="..value)
  34.     file.close()
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement