Posted 29 March 2012 - 10:33 AM
What's this for?
Saving data, without having to deal with files, or all that other crap.
Here's all you have to do to save data:
Functions:
Todo list:
0) Sleep.
1) Finish testing.
1.1) Perhaps some examples?
2) Re-evaluate names.
3) Think about table support; I have some ideas.
4) Anything not covered by 0-3
Known bugs:
Lience: http://www.apache.or...ICENSE-2.0.html
Downloads: pastie, pastebin (pastebin get vhAGg4VB) Zip with limited test script: [attachment=122:vault.zip]
Saving data, without having to deal with files, or all that other crap.
Here's all you have to do to save data:
os.loadAPI("vault")
vault.setDir("/.vault") -- The default, but overriding it will not cause it to revert once the program ends, so you more or less have to use this, or openFile.
local db = vault.open("myprogram.dat")
-- Now use db as a table to save stuff. Note that vault does not support tables yet, and will error upon any bad datatype (function, table).
db[1] = "cake!"
db.cake = true
db[true] = "cake"
-- The next time you open the vault, your data will* be there.
* Assuming no bugs and files not deleted.Functions:
- v = vault.open(name) or vault.openFile(name, file) Creates a new vault object to store data in.
- vault.flush(v) 're'-saves the data using the internal representation, removing any void entries.
- vault.setMode(v, mode) [none, append, hybrid] Mode explanation, and reasons for usage: none: There isn't really any reason to use this over getRaw(). append: Will save data every line, by appending it to the file. hybrid: Same as append, but once HybridN changes have been made, it'll flush.
- t = vault.getRaw(v) Returns the raw table of data.
- dir = vault.getDir() Returns the directory used to store data.
- vault.setDir(dir) Changes the directory used to store data * Existing objects will not change their directory.
- vault.setHybridN(v, n) Sets the number of changes before a flush, when using the hybrid mode.
- vault.reload(v) Re-loads a vault from a file. (any changes to the raw table will be lost)
Todo list:
0) Sleep.
1) Finish testing.
1.1) Perhaps some examples?
2) Re-evaluate names.
3) Think about table support; I have some ideas.
4) Anything not covered by 0-3
Known bugs:
- Error messages are unhelpful (assumes correct arguments 100% of the time). I'm working on this.
- Errors unless you use vault.setDir() first. (if the directory doesn't exist)
Lience: http://www.apache.or...ICENSE-2.0.html
Downloads: pastie, pastebin (pastebin get vhAGg4VB) Zip with limited test script: [attachment=122:vault.zip]