I just ran across something that I don’t know the best way to code around…
If you write a function to write convert a table to JSON and write the resulting string to a file and then read it back in, it’s ok…
If you add a table element “foo” for example to the table and read it back in, foo is gone. The JSON code overwrites the new definition of the table (without foo) and replaces it with the one that was saved.
local contents = file:read( "\*a" ) AppSettings = json.decode(contents);
The only way I can think of to load a previously saved table into the new one is to read it into a temp table and copy every element in the temp table to the active table.
I can’t test for the foo element in the table because it isn’t even there.
Is there a way to test to see if foo exists in a table?
So, if you release an update and you have this save / restore function built in, how can you make sure the next rev does not lose the elements that were added to the table to make the next rev?
Any suggestions?
Perhaps there should be a non-destructive version of json.decode() that would parse the table string and apply the values in the string, and not kill the previous table elements, unless they are overwritten by data in the JSON string?