2021-02-16 13:31:34 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2021-02-09 17:15:54 -05:00
|
|
|
//
|
|
|
|
|
// LUASNAP
|
|
|
|
|
//
|
2021-02-16 13:31:34 -05:00
|
|
|
// A lua interpreter that can be checkpointed (snapshotted). This makes it
|
|
|
|
|
// possible to roll the entire interpreter back to a previously-snapshotted
|
|
|
|
|
// state.
|
2021-02-09 17:15:54 -05:00
|
|
|
//
|
2021-03-01 18:10:40 -05:00
|
|
|
// To accomplish this, we use eris serialization. This is messy and not
|
|
|
|
|
// very modular, but it does work.
|
2021-02-09 17:15:54 -05:00
|
|
|
//
|
2021-02-16 13:31:34 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2021-02-09 17:15:54 -05:00
|
|
|
|
|
|
|
|
#ifndef LUASNAP_HPP
|
|
|
|
|
#define LUASNAP_HPP
|
|
|
|
|
|
2021-03-05 14:20:21 -05:00
|
|
|
#include "StreamBuffer.hpp"
|
2021-02-09 17:15:54 -05:00
|
|
|
#include "luastack.hpp"
|
|
|
|
|
|
|
|
|
|
class LuaSnap {
|
|
|
|
|
private:
|
|
|
|
|
lua_State *state_;
|
2021-03-05 14:20:21 -05:00
|
|
|
StreamBuffer snapshot_;
|
2021-02-09 17:15:54 -05:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
LuaSnap();
|
|
|
|
|
~LuaSnap();
|
|
|
|
|
|
|
|
|
|
// Get the lua intepreter.
|
|
|
|
|
//
|
|
|
|
|
lua_State *state() const { return state_; }
|
|
|
|
|
|
2021-03-02 18:58:50 -05:00
|
|
|
// Serialize the state of the lua interpreter.
|
|
|
|
|
//
|
2021-03-05 14:20:21 -05:00
|
|
|
void serialize(StreamBuffer *sb);
|
2021-03-02 18:58:50 -05:00
|
|
|
|
|
|
|
|
// Restore the the lua interpreter given a serialized state.
|
|
|
|
|
//
|
2021-03-05 14:20:21 -05:00
|
|
|
void deserialize(StreamBuffer *sb);
|
2021-03-02 18:58:50 -05:00
|
|
|
|
2021-02-09 17:15:54 -05:00
|
|
|
// Return true if there's a saved snapshot.
|
|
|
|
|
//
|
|
|
|
|
bool have_snapshot() const;
|
|
|
|
|
|
|
|
|
|
// snapshot the state of the lua interpreter.
|
|
|
|
|
//
|
|
|
|
|
// If there is already a snapshot, this panics.
|
|
|
|
|
//
|
|
|
|
|
void snapshot();
|
|
|
|
|
|
|
|
|
|
// Rollback the lua intepreter to the snapshotted state.
|
|
|
|
|
//
|
|
|
|
|
// If there is no snapshot, this panics.
|
|
|
|
|
//
|
|
|
|
|
void rollback();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // LUASNAP_HPP
|