pioneerspacesim/pioneer — pull request #715 by robn (2011-10-22 21:24:27+00:00)
Title: Serialize support for Lua-based objects

Metatables, function (method) fields, etc don't really serialize, making it hard for Lua-based objects to be serialized by modules. This allows a "class" to provide a Serialize and Unserialize function to convert objects into primitive types and back again on save/load.

To use, add `class = "foo"` to the object's metatable. On game save, `foo.Serialize()` will be called with the object as its only arg. Whatever the function returns will be serialized and saved like normal. On load, that serialized data will be handed to `foo.Unserialize()`. Whatever is returned will be given to the module unserializer like normal.