lua-users home
lua-l archive

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


It was thus said that the Great Egor Skriptunoff once stated:
> 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.

  One way to save the Lua state is to provide a custom allocator to Lua that
always allocates from the same address range for Lua.  It would then be a
simple matter to save said address range to a file and restore it.  The
trick then would be to somehow resume the Lua VM from this saved state.

  -spc