Created
May 21, 2014 17:20
-
-
Save LennyPenny/a7bcb8577e26268dfffc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class "database" { | |
public { | |
___onLoaded = function(self) | |
self:load() | |
end; | |
addTable = function(self, name) | |
self.tables[name] = self.tables[name] or {} | |
self:save() | |
end; | |
updateTable = function(self, tbl, data) | |
if not self.tables[tbl] or not data then return end | |
self.tables[tbl] = data | |
self:save() | |
end; | |
getTable = function(self, name) | |
return self.tables[name] | |
end; | |
}; | |
private { | |
tables = {}; | |
lastSaved = 0; | |
save = function(self) | |
cookie.Set("secreet", util.TableToJSON(self.tables)) | |
self.lastSaved = CurTime() | |
end; | |
load = function(self) | |
local tmpData = cookie.GetString("secreet", "nope") | |
if tmpData == "nope" then return end | |
self.tables = util.JSONToTable(tmpData) | |
end; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment