Home > lstate

lstate

Lstate is a project mainly written in Lua, based on the View license.

Data saving for Lua

h1. lstate

lstate is a Lua library which allows easy and painless storing of tables in Lua.

h2. Dependencies

  • "LuaFilesystem":http://github.com/keplerproject/luafilesystem
  • (optional) "LuaBins":http://github.com/agladysh/luabins (if available, adds functions loadbinary and storebinary)

h2. How to install (with LuaRocks)

Run the command luarocks install state

h2. 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 FilesLua5.1.

h2. How to use

Take a look at this example:

bc. 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?

Previous:Dependencias