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, "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 stderr",
+ llvm::inconvertibleErrorCode());
+ }
+
+ lua_pop(m_lua_state, 1);
+ return llvm::Error::success();
+}
">>> ", "..> ", true, debugger.GetUseColor(), 0,
*this, nullptr),
m_script_interpreter(script_interpreter) {
+ llvm::cantFail(m_script_interpreter.GetLua().ChangeIO(
+ debugger.GetOutputFile().GetStream(),
+ debugger.GetErrorFile().GetStream()));
llvm::cantFail(m_script_interpreter.EnterSession(debugger.GetID()));
}
--- /dev/null
+# REQUIRES: lua
+# UNSUPPORTED: lldb-repro
+#
+# RUN: cat %s | %lldb --script-language lua 2> %t.stderr > %t.stdout
+# RUN: cat %t.stdout | FileCheck %s --check-prefix STDOUT
+# RUN: cat %t.stderr | FileCheck %s --check-prefix STDERR
+script
+file = lldb.SBFile(2, "w", false)
+lldb.debugger:SetOutputFile(file)
+io.write(95000 + 126, "\n")
+quit
+script
+io.write(95000 + 14, "\n")
+# STDOUT: 95126
+# STDOUT-NOT: 95014
+# STDERR: 95014