Advertisement
Theshadow989

Test File 4 (config)

May 2nd, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. local config = {
  2.         osVersion = 'Alpha 1.25';
  3.         osColor = 'true';
  4. }
  5.  
  6. function loadConfig()
  7.     local loaded = {}
  8.     if fs.exists('xos/.ini') then
  9.         local file = fs.open('xos/.ini', 'r')
  10.         for line in file.readLine do
  11.             local key, value = line:match('([%w_]+)%s+(.*)')
  12.             loaded[key] = value
  13.         end
  14.         return loaded, file.close()
  15.     else
  16.         return config
  17.     end
  18. end
  19.  
  20. function saveConfig()
  21.     local content = ''
  22.     for k,v in pairs(config) do
  23.         content = content..k..' '..tostring(v)..'\n'
  24.     end
  25.     local file = fs.open('xos/.ini', 'w')
  26.     file.write(content)
  27.     file.close()
  28. end
  29.  
  30. term.setCursorPos(1,1)
  31. term.clear()
  32.  
  33. function displayConfig()
  34.     local content = ''
  35.     for k,v in pairs(config) do
  36.         write(content..k..' '..tostring(v)..'\n')
  37.     end
  38. end
  39.  
  40. config = loadConfig()
  41. displayConfig()
  42. saveConfig()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement