Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions modules/interpreter/src/cpp/Evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Evaluator::Evaluator(Context* aContext, Interface* aInterface, bool haveEventsLo
depth = 0;
_haveEventsLoop = haveEventsLoop;
io = aInterface;
defaultInterface = aInterface;
InCLI = false;
bpActive = false;
clearStacks();
Expand Down Expand Up @@ -204,6 +205,13 @@ Evaluator::getInterface()
{
return io;
}
//======================================================================
// Returns the default (interactive) interface.
Interface*
Evaluator::getDefaultInterface()
{
return defaultInterface ? defaultInterface : io;
}
//=============================================================================
// Returns the ID of the evaluator.
size_t
Expand Down Expand Up @@ -604,7 +612,19 @@ Evaluator::debugCLI()
if (haveEventsLoop()) {
ProcessEventsDynamicFunctionWithoutWait();
}
// If the current interface is not the default (interactive) one
// (e.g., during evalc), temporarily restore the interactive interface
// so that the debug CLI can read user input.
Interface* savedIO = nullptr;
if (io != defaultInterface && defaultInterface != nullptr) {
savedIO = io;
io = defaultInterface;
}
evalCLI();
// Restore the previous interface after the debug session
if (savedIO != nullptr) {
io = savedIO;
}
// After evalCLI() returns, check if debug mode should be exited:
// - If a debug command set bpActive to false, keep it false
// - If script finished without active breakpoint, exit debug mode
Expand Down
9 changes: 9 additions & 0 deletions modules/interpreter/src/include/Evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ class NLSINTERPRETER_IMPEXP Evaluator
* The interface for I/O
*/
Interface* io;
/**
* The default (interactive) interface, saved at construction.
* Used to restore interactive I/O during debug sessions
* when the current interface has been temporarily replaced
* (e.g., by evalc).
*/
Interface* defaultInterface = nullptr;

int exitCode = 0;

Expand Down Expand Up @@ -318,6 +325,8 @@ class NLSINTERPRETER_IMPEXP Evaluator
setInterface(Interface* _io);
Interface*
getInterface();
Interface*
getDefaultInterface();
/**
* Process an AST to form an lvalue in an assignment statement.
* The AST looks like:
Expand Down
Loading