lstate is a Lua library which allows easy and painless storing of tables in Lua.
- LuaFilesystem
- (optional) LuaBins (if available, adds functions loadbinary and storebinary)
Run the command luarocks install state
Put the folder state somewhere in your Lua module path.
On Linux/Mac this is usually something like /usr/local/share/lua/5.1/.
On Windows it’s C:\Program Files\Lua\5.1\.
Take a look at this example:
require("state")
-- initialize our data table
data = {aVariable = ""}
-- if there is a previous state, load it
local st = state.load("exampleStateProgram")
if st then data = st end
-- print the variable
print("Stored variable: "..data.aVariable)
-- store a new value
io.write("Input a value to be stored: ")
data.aVariable = io.read("*line")
-- save the table
state.store("exampleStateProgram", data)
Easy, isn’t it?