monster010

CC - Config API

Apr 20th, 2016
2,175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.57 KB | None | 0 0
  1. -- Config API - (c) monster010
  2. local cfg = {}
  3. local pfad = ""
  4.  
  5. function load(path)
  6.     pfad = path
  7.  
  8.     if fs.exists(pfad) then
  9.         local file = fs.open(pfad, "r")
  10.         cfg = textutils.unserialize(file.readAll())
  11.         file.close()
  12.     else
  13.         create()
  14.     end
  15. end
  16.  
  17. function create()
  18.     local file = fs.open(pfad, "a")
  19.     file.close()
  20. end
  21.  
  22. function save()
  23.     local file = fs.open(pfad, "w")
  24.     file.write(textutils.serialize(cfg))
  25.     file.close()
  26. end
  27.  
  28. function getConfig()
  29.     return cfg
  30. end
  31.  
  32. function get(key)
  33.     return cfg[key]
  34. end
  35.  
  36. function set(key, val)
  37.     cfg[key] = val
  38.     save()
  39. end
Advertisement
Add Comment
Please, Sign In to add comment