diff --git a/src/app/app.cpp b/src/app/app.cpp index ccde1459f..65d718bf3 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -696,6 +696,7 @@ void App::run() if (m_isShell) { StdoutEngineDelegate delegate; AppScripting engine(&delegate); + engine.printLastResult(); Shell shell; shell.run(engine); } diff --git a/src/script/engine.cpp b/src/script/engine.cpp index 2eae72a82..484b21193 100644 --- a/src/script/engine.cpp +++ b/src/script/engine.cpp @@ -423,6 +423,7 @@ Engine::Engine(EngineDelegate* delegate) (void*)this, &on_fatal_handler)) , m_delegate(delegate) + , m_printLastResult(false) { // Set 'on_search_module' as the function to search modules with // require('modulename') on JavaScript. @@ -437,6 +438,11 @@ Engine::~Engine() duk_destroy_heap(m_ctx.handle()); } +void Engine::printLastResult() +{ + m_printLastResult = true; +} + void Engine::eval(const std::string& jsCode) { try { @@ -444,7 +450,8 @@ void Engine::eval(const std::string& jsCode) duk_eval_string(handle, jsCode.c_str()); - if (!duk_is_null_or_undefined(handle, -1)) + if (m_printLastResult && + !duk_is_null_or_undefined(handle, -1)) { m_delegate->onConsolePrint(duk_safe_to_string(handle, -1)); duk_pop(handle); @@ -487,7 +494,8 @@ void Engine::evalFile(const std::string& file) duk_push_string(handle, duk_to_string(handle, -1)); duk_eval_raw(handle, nullptr, 0, DUK_COMPILE_EVAL); - if (!duk_is_null_or_undefined(handle, -1)) + if (m_printLastResult && + !duk_is_null_or_undefined(handle, -1)) { m_delegate->onConsolePrint(duk_safe_to_string(handle, -1)); duk_pop(handle); diff --git a/src/script/engine.h b/src/script/engine.h index c1ff9de11..ec9534a14 100644 --- a/src/script/engine.h +++ b/src/script/engine.h @@ -126,6 +126,7 @@ namespace script { Engine(EngineDelegate* delegate); ~Engine(); + void printLastResult(); void eval(const std::string& jsCode); void evalFile(const std::string& file); @@ -136,6 +137,7 @@ namespace script { private: Context m_ctx; EngineDelegate* m_delegate; + bool m_printLastResult; }; }