diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2020-07-26 19:36:28 +0000 |
commit | cfca06d7963fa0909f90483b42a6d7d194d01e08 (patch) | |
tree | 209fb2a2d68f8f277793fc8df46c753d31bc853b /lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp | |
parent | 706b4fc47bbc608932d3b491ae19a3b9cde9497b (diff) |
Notes
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp b/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp index ecee8cc674f81..acd6128d84c5a 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp @@ -57,3 +57,35 @@ llvm::Error Lua::LoadModule(llvm::StringRef filename) { lua_setglobal(m_lua_state, module_name.GetCString()); return llvm::Error::success(); } + +llvm::Error Lua::ChangeIO(FILE *out, FILE *err) { + assert(out != nullptr); + assert(err != nullptr); + + lua_getglobal(m_lua_state, "io"); + + lua_getfield(m_lua_state, -1, "stdout"); + if (luaL_Stream *s = static_cast<luaL_Stream *>( + luaL_testudata(m_lua_state, -1, LUA_FILEHANDLE))) { + s->f = out; + lua_pop(m_lua_state, 1); + } else { + lua_pop(m_lua_state, 2); + return llvm::make_error<llvm::StringError>("could not get stdout", + llvm::inconvertibleErrorCode()); + } + + lua_getfield(m_lua_state, -1, "stderr"); + if (luaL_Stream *s = static_cast<luaL_Stream *>( + luaL_testudata(m_lua_state, -1, LUA_FILEHANDLE))) { + s->f = out; + lua_pop(m_lua_state, 1); + } else { + lua_pop(m_lua_state, 2); + return llvm::make_error<llvm::StringError>("could not get stderr", + llvm::inconvertibleErrorCode()); + } + + lua_pop(m_lua_state, 1); + return llvm::Error::success(); +} |