mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-18 11:42:47 +00:00
[lua] Close stdin handle when we start running the GUI
This commit is contained in:
parent
cd211ba0fd
commit
0b55dcdb3a
@ -267,9 +267,19 @@ int App::initialize(const AppOptions& options)
|
|||||||
|
|
||||||
#ifdef ENABLE_UI
|
#ifdef ENABLE_UI
|
||||||
m_isGui = options.startUI() && !options.previewCLI();
|
m_isGui = options.startUI() && !options.previewCLI();
|
||||||
|
|
||||||
|
// Notify the scripting engine that we're going to enter to GUI
|
||||||
|
// mode, this is useful so we can mark the stdin file handle as
|
||||||
|
// closed so no script can hang the program if it tries to read from
|
||||||
|
// stdin when the GUI is running.
|
||||||
|
#ifdef ENABLE_SCRIPTING
|
||||||
|
if (m_isGui)
|
||||||
|
m_engine->notifyRunningGui();
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
m_isGui = false;
|
m_isGui = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_isShell = options.startShell();
|
m_isShell = options.startShell();
|
||||||
m_coreModules = std::make_unique<CoreModules>();
|
m_coreModules = std::make_unique<CoreModules>();
|
||||||
|
|
||||||
|
@ -536,6 +536,24 @@ void Engine::destroy()
|
|||||||
L = nullptr;
|
L = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::notifyRunningGui()
|
||||||
|
{
|
||||||
|
// Mark stdin file handle as closed so the following statements
|
||||||
|
// don't hang the program:
|
||||||
|
// - io.lines()
|
||||||
|
// - io.read('a')
|
||||||
|
// - io.stdin:read('a')
|
||||||
|
lua_getglobal(L, "io");
|
||||||
|
lua_getfield(L, -1, "stdin");
|
||||||
|
|
||||||
|
auto p = ((luaL_Stream*)luaL_checkudata(L, -1, LUA_FILEHANDLE));
|
||||||
|
ASSERT(p);
|
||||||
|
p->f = nullptr;
|
||||||
|
p->closef = nullptr;
|
||||||
|
|
||||||
|
lua_pop(L, 2);
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::printLastResult()
|
void Engine::printLastResult()
|
||||||
{
|
{
|
||||||
m_printLastResult = true;
|
m_printLastResult = true;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2018-2023 Igara Studio S.A.
|
// Copyright (C) 2018-2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2018 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -97,6 +97,9 @@ namespace app {
|
|||||||
m_delegate = delegate;
|
m_delegate = delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called if the GUI is going to be started.
|
||||||
|
void notifyRunningGui();
|
||||||
|
|
||||||
void printLastResult();
|
void printLastResult();
|
||||||
bool evalCode(const std::string& code,
|
bool evalCode(const std::string& code,
|
||||||
const std::string& filename = std::string());
|
const std::string& filename = std::string());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user