lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



I would recommend another (simpler) kind of mechanism:

- have all of your application state in a separate table (or in the _G)
- store that table when exiting
- read that table when re-launching, and if it already contains stuff, rebuild your application's visual appearance accordingly - in regular exit (truly quitting the software) erase the state table so the next launch will be "virgin"

At least Maemo had this kind of a framework, though very roughly implemented. With Lua, it can be simple. It requires special attention from the scripts you are running, though. And if it's a GUI, you need to make some assumptions s.a. not "hybernating" when a dialog is active. Otherwise there's waaaay too much state to be restored (had this dialog open, with this field selected, with these entries edited....) Just consider dialogs invocation-temporal.

Lua Lanes supports this kind of a mechanism in the thread cancellation (you can get the globals of a cancelled thread). But you can implement it also on bare Lua, or with Pluto.

Things s.a. userdata cannot be serialized, of course. They can have a lifespan within each invocation only.

- asko



kathrin_69@gmx.de kirjoitti 20.3.2009 kello 13:10:

Hi,

I want to save the state of a Lua VM to a file to re-load and restart execution later.

Three options come to my mind:

1. Serializing the global index table of the VM. I even found a library called "Pluto" which promises to do this.

2. Trying to make a deep copy of the lua_State* pointing to a VM and save/load the binary data.

3. Trying to overwrite malloc/free for the Lua.dll, place all memory the VM holds in an pre-allocated chunk. Save and re-load that whole chunk. I'm not sure If I'm yet experienced (in C/C++) enough to get this done. Probably not.



My Questions are:

1. Which of that options will work or which one are used and which not?
2. Are there any other options I missed?
3. Which option is most promising in terms of time and complexity?
4. Are there any other helper libraries (beside Pluto) which helps doing one of the options?

Thank you!

Regards
Joerg