Exists your game state really only in lua ? What about references (user data) to external (i.e. C++/C) data ?
I'm developing a game which uses lua for scripting. I am at a point in development where I want to have save files/states and I am wondering what's the best solution. My scripts usually have a local table where most of the variables reside, I use no coroutines in my scripts. Is it a good idea to somehow iterate through the lua stack and save the variables to file?
I have searched around a bit and found a library called pluto but I am not very confident that it will work with the latest lua build (5.2). Moreover it seems to have issues with 64bit systems.
Any thoughts on lua stack saving is greatly appreciated.
I use a simple serialization=>deserialization=>post processing mechanism to save my game state (mostly lua) and reconnect it with engine related data (C++) after reloading it. An other consideration is, that you should take care of game related data which will change quite often during development. I.e. some item data or combat tables which changes frequently, saving this with the lua stack will render saved game useless, and you need saved games once you reach a late development stage.
An other approach, though more expensive, is to export/import your game state. This is similar to de-/serialization, but much more loosly (and error prone), think of a kind of simple script format which is needed to load your game and insert all entites etc. into the game (de-/serialization is more like an 1:1 mapping). This way frequent changes to the game or game related meta data can be managed really easily.