Sign in to follow this  
BS-er

Saving and restoring the essentials of a Lua state

Recommended Posts

Scenerio: A game is running a number of script coroutines. The player wants to save the game, and pick it up later. In order to do so, the states of all coroutines (where they yield) must be saved and restored, in addition to data in variables. when the player loads the saved game later, each coroutine resumes at the point it last yielded, even if that occurs several calls deeper than the actual coroutine. I have to believe that this is a trivial matter, and I would think that it is a very common need. I didn't have much luck finding a solution for Lua. The ideal would be a simple solution: SaveToStateFile(lua_State* state, const char* StateFile); lua_State* CreateFromStateFile(const char* ScriptFile, const char* StateFile); I wouldn't expect to save the byte code itself, just the data needed for the bytecode to resume. Of course one could only hope its that easy. Anyone know of a straightforward approach for doing what I'm trying to do, in Lua or any other language? [Edited by - BS-er on July 11, 2007 8:14:40 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
A quick bit of googling about leads me to Pluto which looks like it might well do the job.

Indeed, this situation is more or less exactly what it's for. Tell me if you have any questions about it.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Tell me if you have any questions about it.


I may make you regret that offer ;). I can't find much information on Pluto out in the Google world.

Here are the things that I'm wondering?
1) Has been shown to work with the latest version of Lua?
2) Any testemonial comments by someone who is using Pluto?

[Edited by - BS-er on July 13, 2007 8:20:28 PM]

Share this post


Link to post
Share on other sites
1. I haven't tested it with 5.1.2, but it is unlikely to have problems with that version. It works fine with 5.1.

2. I'd suggest searching for "pluto" in the lua-users mailing list archive.

Share this post


Link to post
Share on other sites
Thanks for the information. Just a few other things I'm wondering, if you don't mind too much.

1) My ideal goal would be to set things up for no-brainer script persistance. In other words, it would be nice for my non-programmer script authors to write a script, full of coroutines, functions, variables etc., but not write special script code to persist and unpersist the Lua state for all that stuff. The details of persistance are kept from them or made very easy, i.e. some very minimal boilerplate. I wonder is that achievable using Lua and/or C, even if I need to modify the Pluto code?

2) If I know the script will be available when the saved game is loaded, can the persisted file be kept smaller by not saving all the functions themselves to it? And is there a no-brainer approach to doing that? I think the README suggests that, but I just wanted to be sure I'm interpreting it correctly.

Thanks for any help or suggestions you can offer.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this