pioneerspacesim/pioneer — pull request #1302 by Brianetta (2012-06-23 20:45:01+00:00)
Title: Lua module save versioning

This doesn't have to be merged immediately, since as I write this request only two library scripts have been touched.

The Lua modules in Pioneer have no saved game versioning at all. Before Pioneer advances to the stage where we would expect players to be able to load games between versions, I'd like to get all the modules to be able to determine whether incoming serialized data is from a different version of the module, so that it can either upgrade or throw a tantrum as appropriate.

This is much easier than what will happen if we don't take control now: Modules will analyse the saved data structure, and attempt to guess what changes, if any, are needed.

Characters and FlightLog now have some basic structure; they have a version (`local VERSION = 1`) in a prominent location on the first line of the script. `serialize()` stores `VERSION` in the table that it returns, and `unserialize()` has the job of upgrading data if necessary, or throwing an error.

If people see a better approach than this, feel free to educate me. If I don't get any particularly negative feedback over the next interval *t*, then I'll get on and add similar code to the other modules.