[aseprite] 154/196: Avoid printing the last script result when we run a script from UI

Tobias Hansen thansen at moszumanska.debian.org
Wed Apr 20 18:50:14 UTC 2016


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit de8ef623a685726f6db5e87d860c941803075204
Author: David Capello <davidcapello at gmail.com>
Date:   Wed Apr 6 16:56:10 2016 -0300

    Avoid printing the last script result when we run a script from UI
---
 src/app/app.cpp       |  1 +
 src/script/engine.cpp | 12 ++++++++++--
 src/script/engine.h   |  2 ++
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/app/app.cpp b/src/app/app.cpp
index ccde145..65d718b 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 2eae72a..484b211 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 c1ff9de..ec9534a 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;
   };
 
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list