2

I've seen in some various IOS games Lua scripts being used for saving user settings, and data. I can't figure out how to do this myself, does anyone know of an open source project or example of how to achieve this?

Are people just re-writing the lua scripts programatically? Or is there some way in Lua to rewrite or save data in a lua script? I'm really confused on how this is achieved with lua. Please help me out!

AwDogsGo2Heaven
  • 952
  • 11
  • 26
  • 2
    It sounds like you're trying to serialize data, like save files, that can be read back later, is that correct? You may want to look [here](http://lua-users.org/wiki/TableSerialization) – Alex Nov 08 '12 at 17:33

1 Answers1

2

Are people just re-writing the lua scripts programatically?

Yes, it's really very simple. You store your setting data or whatever in a table. You then write that table to a file using simple Lua code. The file you write is a Lua script that, when executed, returns the table.

So your script looks like this:

return
{
  setting = true,
  width = 640,
  height = 480,
}

The code needed to write such serialization is not difficult to write (so long as you don't have tables referencing themselves, directly or indirectly). There are a variety of implementations of this.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • So if I wanted a human readable file, that I could edit manually when necessary, I could use for example this one on the website: SaveTableToFile - save table to file/str; load table from file/str And it would simply dump the table into a file, including the name of variable and data? – AwDogsGo2Heaven Nov 08 '12 at 19:52