lua-users home
lua-l archive

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


We do something like this for CorsixTH. Essentially walking the object graph from _G persisting everything. References to things already saved and calling persist / depersist metamethods to handle userdata. An overload of dofile was added so that we could restore function references correctly. A limitation is that shared upvalues become disconnected.

https://github.com/CorsixTH/CorsixTH/wiki/Persistence

https://github.com/CorsixTH/CorsixTH/blob/master/CorsixTH/Src/persist_lua.cpp

I have a work in progress pull request to 5.4 compatibility that cleans it up a little bit. Feel free to use it as a starting point. 

On Sun., Aug. 16, 2020, 3:23 p.m. Egor Skriptunoff, <egor.skriptunoff@gmail.com> wrote:
Hi!

There is an interesting SO question:
https://stackoverflow.com/questions/63365401/resuming-lua-script-using-its-c-api

OP uses Lua in his game and wants to be able to get (using Lua C API)
current Lua VM snapshot in some serializable form
for saving it inside a savegame file.
When the saved game is loaded, Lua VM resumes from the saved snapshot.
It looks like a useful feature for embeddable language.
It would also allow running a long-lasting script on one computer,
then pausing it and resuming the calculations on another computer.

The idea might be too hard to implement, but it surely worth discussing.