lstate
lstate is a Lua library which allows easy and painless storing of tables in Lua.
Dependencies
- LuaFilesystem
- (optional) LuaBins (if available, adds functions loadbinary and storebinary)
How to install (with LuaRocks)
Run the command luarocks install state
How to install (Manually)
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\.
How to use
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?