Saving data

DEPRECATED

Writing files to store data (like highscores) in your project directory is a commonly used technique.

However, this technique has the drawback that if your project becomes zipped, it will no longer be able to save data as it is no longer providing a "personal" directory.

In order to provide a solution to this problem, the .98 API of Luxinia introduces a class named DataRegistry? which is offering the services that you need for this case. It also offers convenient functions to write and read data that is stored in tables.

Saving and loading table data:

Saving and loading table data is pretty easy using this class:

-- our default score table
scores = {
  {name = "aname", score = 100},
  {name="anothername", score = 90}
}

-- load the file, if no such file could be found, 
-- it will use the score table that is passed
scores = 
  DataRegistry.loadtable("myproject","highscores",scores)

-- do somthing now with the table (i.e. add new entries)

-- save the score table
DataRegistry.savetable("myproject","highscores",scores)

Both functions (savetable / loadtable) offer the most simple form to keep consistent data. The first argument (here "myproject") is the projecttitle. It should be a unique identifier for your project data. The following string (here "highscores" is the filename that is going to be used.

The projectname and the filename may also contain folders like "luxinia/actinoids" or "scores/level01.lua" etc.

Accessing files

Of course you can also access files in these directories directly. Either, the full filepath can be obtained by calling DataRegistry?.getpath(projectpath,filename) or, if it should be opened directly, the filehandle can be obtained by calling DataRegistry?.open(projectpath,filename,[mode]), where the mode can either be nil (opening file for reading only) or any other mode as documented in the io lib of lua ("w"/"wb"/etc.)

DEPRECATED