mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-29 12:32:52 +00:00
Avoid printing the last script result when we run a script from UI
This commit is contained in:
parent
21921fdfd5
commit
de8ef623a6
@ -696,6 +696,7 @@ void App::run()
|
||||
if (m_isShell) {
|
||||
StdoutEngineDelegate delegate;
|
||||
AppScripting engine(&delegate);
|
||||
engine.printLastResult();
|
||||
Shell shell;
|
||||
shell.run(engine);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user