Advertisement
theoriginalbit

ccConfig: Example — Basic

Feb 6th, 2013
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. os.loadAPI("/ccConfig")
  2.  
  3. term.clear()
  4. term.setCursorPos(1,1)
  5.  
  6. local conf = ccConfig.new("config.cfg", "Basic Config Example")
  7. local running
  8. local msg
  9. local rate
  10. local bgcolor
  11. local txtcolor
  12.  
  13. local function loadConfig()
  14.   conf:load()
  15.  
  16.   running = conf:getBoolean("canRun", "no")
  17.   msg = conf:getString("welcomeMessage", "Hello World")
  18.   rate = conf:getNumber("refreshRate", 2.5)
  19.   bgcolor = conf:getColor("background", colors.black)
  20.   txtcolor = conf:getColour("text", "colors.white")
  21.  
  22.  
  23.   conf:addCommentForKey("canRun", "Tells the program if it is allowed to run")
  24.   conf:addCommentForKey("refreshRate", "Tells the program how often to check inputs again")
  25.  
  26.   conf:save()
  27. end
  28.  
  29. local function resetConfig()
  30.   conf:reset()
  31.   conf:save()
  32. end
  33.  
  34. loadConfig()
  35.  
  36. print("This should display whats in the configs:")
  37. print("canRun: "..tostring(running)) --> whats in config or false
  38. print("msg: "..msg) --> whats in config or "Hello World"
  39. print("rate: "..rate) --> whats in config or 2.5
  40. print("bg: "..bgcolor)
  41. print("text: "..txtcolor)
  42. print("canRun key exists: "..tostring(conf:containsKey("canRun")))
  43. print("thisThing key exists: "..tostring(conf:containsKey("thisThing")))
  44.  
  45. resetConfig()
  46. loadConfig()
  47.  
  48. print("\nThis should display whats the default values are:")
  49. print("canRun: "..tostring(running)) --> whats in config or false
  50. print("msg: "..msg) --> whats in config or "Hello World"
  51. print("rate: "..rate) --> whats in config or 2.5
  52. print("bg: "..bgcolor)
  53. print("text: "..txtcolor)
  54. print("canRun key exists: "..tostring(conf:containsKey("canRun")))
  55. print("thisThing key exists: "..tostring(conf:containsKey("thisThing")))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement