Preference Library - Save data to Files ( tables, numbers, strings and boolean )

615
Vote up!

This small useful module can be used to store and retrieve values across different app sessions.
A lot of people found it useful in Code Exchange 1, so am reposting it here

You can save TABLES, NUMBERS, STRINGS or BOOLEANS.

FUNCTIONS
preference.save
preference.getValue
preference.getAllValues
preference.print
preference.printAll

USAGE AND EXAMPLES

local preference = require "preference"

--Store numbers
preference.save{a=1}
value = preference.getValue("a")

--Store strings
preference.save{b="1"}
value = preference.getValue("b")

--Store Boolean
preference.save{c=true}
value = preference.getValue("c")

--Store Tables
preference.save{d = {1,"2",true}}
value = preference.getValue("d")

--Tables with multiple levels of subtables can also be stored and retrieved.

Category: 
Contributor: 
SatheeshJM