CoolisTheName007

Untitled

Apr 24th, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. include'kernel.class'
  2. local check=require'kernel.checker'
  3. local dump=require'utils.serpent'.dump
  4. local util=require'kernel.util'
  5. class.Var()
  6. local p=setmetatable({},{__mode='k'})
  7. function Var:__init(file,opt)
  8. p[self]={}
  9. p[self].file=file
  10. local dir=loadreq.getDir(p[self].file)
  11. if not fs.exists(dir) then fs.makeDir(dir) end
  12. if not fs.exists(file) then self:setAll{} end
  13. end
  14.  
  15. function Var:getAll()
  16. local f=io.open(p[self].file,'r')
  17. local s=f:read'*a'
  18. f:close()
  19. local t=loadstring(s)()
  20. return t
  21. end
  22.  
  23. function Var:setAll(t)
  24. local f=io.open(p[self].file,'w')
  25. local s=f:write(dump(t))
  26. f:close()
  27. end
  28.  
  29. function Var:__get(k)
  30. local t=self:getAll()
  31. if not t then t={} self:setAll(t) end
  32. return t[k]
  33. end
  34. function Var:__set(k,v)
  35. local t=self:getAll()
  36. t[k]=v
  37. self:setAll(t)
  38. return true
  39. end
  40. return Var
Advertisement
Add Comment
Please, Sign In to add comment