What is the correct way of restoring a cling intepreter to a previous state in C++?

I am trying to save the state of a cling intepreter, process() a variable amount of code on it, then restore the previous state getting ready for the next chunk of code.

I have been looking into Interpreter::getLastTransaction, Interpreter::getLastestTransaction, Interpreter::getCurrentTransaction (I do not understand the difference between them) and the Interpreter::unload(Transaction &) methods. I discarded Interpreter::unload(unsigned) as I do not know how to count the transactions.

The getXXXTransaction functions all return a const pointer, which is not compatible with the unload function. I tried to remove the const via const_cast, but I ended up with a segfault at runtime.

Thank you for the help!

PS. what about a copy constructor for the Interpreter class? How feasible and fast would that be?

Maybe @Axel can give you details on this particular question

Hi,

You will probably want to spawn a new interpreter that “inherits” the state of another existing interpreter. This works to some extent - you might need to contribute patches :wink: See http://cling.web.cern.ch/cling/doxygen/classcling_1_1Interpreter.html#a23337fd5559625bbb7ec38f8c2904ec0

Cheers, Axel.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.