Author: Jonas Devlieghere
Date: 2026-02-24T16:49:41-08:00
New Revision: 5cb8191595d3331d9d333cd441b63f2af535760a

URL: 
https://github.com/llvm/llvm-project/commit/5cb8191595d3331d9d333cd441b63f2af535760a
DIFF: 
https://github.com/llvm/llvm-project/commit/5cb8191595d3331d9d333cd441b63f2af535760a.diff

LOG: [lldb] Rename Lua -> LuaState (NFC) (#183218)

Rename Lua to LuaState to avoid conflicts between Lua.h and lua.h on
case-insensitive file systems.

Added: 
    lldb/source/Plugins/ScriptInterpreter/Lua/LuaState.cpp
    lldb/source/Plugins/ScriptInterpreter/Lua/LuaState.h

Modified: 
    lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
    lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
    lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
    lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp

Removed: 
    lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
    lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h


################################################################################
diff  --git a/lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt 
b/lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
index 498bd97839510..ecfc7648c7ce4 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
+++ b/lldb/source/Plugins/ScriptInterpreter/Lua/CMakeLists.txt
@@ -1,5 +1,5 @@
 add_lldb_library(lldbPluginScriptInterpreterLua PLUGIN
-  Lua.cpp
+  LuaState.cpp
   ScriptInterpreterLua.cpp
 
   LINK_LIBS

diff  --git a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Lua/LuaState.cpp
similarity index 84%
rename from lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
rename to lldb/source/Plugins/ScriptInterpreter/Lua/LuaState.cpp
index 8dad22d077be3..b07f5a0519852 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Lua/LuaState.cpp
@@ -1,4 +1,4 @@
-//===-- Lua.cpp 
-----------------------------------------------------------===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,7 +6,7 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#include "Lua.h"
+#include "LuaState.h"
 #include "SWIGLuaBridge.h"
 #include "lldb/Host/FileSystem.h"
 #include "lldb/Utility/FileSpec.h"
@@ -31,7 +31,7 @@ static int lldb_print(lua_State *L) {
   return 0;
 }
 
-Lua::Lua() : m_lua_state(luaL_newstate()) {
+LuaState::LuaState() : m_lua_state(luaL_newstate()) {
   assert(m_lua_state);
   luaL_openlibs(m_lua_state);
   luaopen_lldb(m_lua_state);
@@ -39,12 +39,12 @@ Lua::Lua() : m_lua_state(luaL_newstate()) {
   lua_setglobal(m_lua_state, "print");
 }
 
-Lua::~Lua() {
+LuaState::~LuaState() {
   assert(m_lua_state);
   lua_close(m_lua_state);
 }
 
-llvm::Error Lua::Run(llvm::StringRef buffer) {
+llvm::Error LuaState::Run(llvm::StringRef buffer) {
   int error =
       luaL_loadbuffer(m_lua_state, buffer.data(), buffer.size(), "buffer") ||
       lua_pcall(m_lua_state, 0, 0, 0);
@@ -59,7 +59,8 @@ llvm::Error Lua::Run(llvm::StringRef buffer) {
   return e;
 }
 
-llvm::Error Lua::RegisterBreakpointCallback(void *baton, const char *body) {
+llvm::Error LuaState::RegisterBreakpointCallback(void *baton,
+                                                 const char *body) {
   lua_pushlightuserdata(m_lua_state, baton);
   const char *fmt_str = "return function(frame, bp_loc, ...) {0} end";
   std::string func_str = llvm::formatv(fmt_str, body).str();
@@ -76,9 +77,9 @@ llvm::Error Lua::RegisterBreakpointCallback(void *baton, 
const char *body) {
 }
 
 llvm::Expected<bool>
-Lua::CallBreakpointCallback(void *baton, lldb::StackFrameSP stop_frame_sp,
-                            lldb::BreakpointLocationSP bp_loc_sp,
-                            StructuredData::ObjectSP extra_args_sp) {
+LuaState::CallBreakpointCallback(void *baton, lldb::StackFrameSP stop_frame_sp,
+                                 lldb::BreakpointLocationSP bp_loc_sp,
+                                 StructuredData::ObjectSP extra_args_sp) {
 
   lua_pushlightuserdata(m_lua_state, baton);
   lua_gettable(m_lua_state, LUA_REGISTRYINDEX);
@@ -87,7 +88,8 @@ Lua::CallBreakpointCallback(void *baton, lldb::StackFrameSP 
stop_frame_sp,
       m_lua_state, stop_frame_sp, bp_loc_sp, extra_args_impl);
 }
 
-llvm::Error Lua::RegisterWatchpointCallback(void *baton, const char *body) {
+llvm::Error LuaState::RegisterWatchpointCallback(void *baton,
+                                                 const char *body) {
   lua_pushlightuserdata(m_lua_state, baton);
   const char *fmt_str = "return function(frame, wp, ...) {0} end";
   std::string func_str = llvm::formatv(fmt_str, body).str();
@@ -104,8 +106,8 @@ llvm::Error Lua::RegisterWatchpointCallback(void *baton, 
const char *body) {
 }
 
 llvm::Expected<bool>
-Lua::CallWatchpointCallback(void *baton, lldb::StackFrameSP stop_frame_sp,
-                            lldb::WatchpointSP wp_sp) {
+LuaState::CallWatchpointCallback(void *baton, lldb::StackFrameSP stop_frame_sp,
+                                 lldb::WatchpointSP wp_sp) {
 
   lua_pushlightuserdata(m_lua_state, baton);
   lua_gettable(m_lua_state, LUA_REGISTRYINDEX);
@@ -113,7 +115,7 @@ Lua::CallWatchpointCallback(void *baton, lldb::StackFrameSP 
stop_frame_sp,
       m_lua_state, stop_frame_sp, wp_sp);
 }
 
-llvm::Error Lua::CheckSyntax(llvm::StringRef buffer) {
+llvm::Error LuaState::CheckSyntax(llvm::StringRef buffer) {
   int error =
       luaL_loadbuffer(m_lua_state, buffer.data(), buffer.size(), "buffer");
   if (error == LUA_OK) {
@@ -130,7 +132,7 @@ llvm::Error Lua::CheckSyntax(llvm::StringRef buffer) {
   return e;
 }
 
-llvm::Error Lua::LoadModule(llvm::StringRef filename) {
+llvm::Error LuaState::LoadModule(llvm::StringRef filename) {
   const FileSpec file(filename);
   if (!FileSystem::Instance().Exists(file)) {
     return llvm::make_error<llvm::StringError>("invalid path",
@@ -158,7 +160,7 @@ llvm::Error Lua::LoadModule(llvm::StringRef filename) {
   return llvm::Error::success();
 }
 
-llvm::Error Lua::ChangeIO(FILE *out, FILE *err) {
+llvm::Error LuaState::ChangeIO(FILE *out, FILE *err) {
   assert(out != nullptr);
   assert(err != nullptr);
 

diff  --git a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h 
b/lldb/source/Plugins/ScriptInterpreter/Lua/LuaState.h
similarity index 81%
rename from lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
rename to lldb/source/Plugins/ScriptInterpreter/Lua/LuaState.h
index 908f98164c0f5..4c188f06a329c 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Lua/Lua.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Lua/LuaState.h
@@ -1,4 +1,4 @@
-//===-- ScriptInterpreterLua.h ----------------------------------*- C++ 
-*-===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,11 +6,9 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#ifndef LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_LUA_LUA_H
-#define LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_LUA_LUA_H
+#ifndef LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_LUA_LUASTATE_H
+#define LLDB_SOURCE_PLUGINS_SCRIPTINTERPRETER_LUA_LUASTATE_H
 
-#include "lldb/API/SBBreakpointLocation.h"
-#include "lldb/API/SBFrame.h"
 #include "lldb/Core/StructuredDataImpl.h"
 #include "lldb/lldb-types.h"
 #include "llvm/ADT/StringRef.h"
@@ -18,18 +16,16 @@
 
 #include "lua.hpp"
 
-#include <mutex>
-
 namespace lldb_private {
 
 extern "C" {
 int luaopen_lldb(lua_State *L);
 }
 
-class Lua {
+class LuaState {
 public:
-  Lua();
-  ~Lua();
+  LuaState();
+  ~LuaState();
 
   llvm::Error Run(llvm::StringRef buffer);
   llvm::Error RegisterBreakpointCallback(void *baton, const char *body);

diff  --git 
a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
index 0a0f19f7d09b9..fb85245c98e88 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.cpp
@@ -7,7 +7,7 @@
 
//===----------------------------------------------------------------------===//
 
 #include "ScriptInterpreterLua.h"
-#include "Lua.h"
+#include "LuaState.h"
 #include "lldb/Breakpoint/StoppointCallbackContext.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/PluginManager.h"
@@ -45,7 +45,7 @@ class IOHandlerLuaInterpreter : public IOHandlerDelegate,
                           true, debugger.GetUseColor(), 0, *this),
         m_script_interpreter(script_interpreter),
         m_active_io_handler(active_io_handler) {
-    llvm::cantFail(m_script_interpreter.GetLua().ChangeIO(
+    llvm::cantFail(m_script_interpreter.GetLuaState().ChangeIO(
         debugger.GetOutputFileSP()->GetStream(),
         debugger.GetErrorFileSP()->GetStream()));
     llvm::cantFail(m_script_interpreter.EnterSession(debugger.GetID()));
@@ -98,7 +98,7 @@ class IOHandlerLuaInterpreter : public IOHandlerDelegate,
     StreamString str;
     lines.Join("\n", str);
     if (llvm::Error E =
-            m_script_interpreter.GetLua().CheckSyntax(str.GetString())) {
+            m_script_interpreter.GetLuaState().CheckSyntax(str.GetString())) {
       std::string error_str = toString(std::move(E));
       // Lua always errors out to incomplete code with '<eof>'
       return error_str.find("<eof>") == std::string::npos;
@@ -139,7 +139,7 @@ class IOHandlerLuaInterpreter : public IOHandlerDelegate,
         io_handler.SetIsDone(true);
         return;
       }
-      if (llvm::Error error = m_script_interpreter.GetLua().Run(data)) {
+      if (llvm::Error error = m_script_interpreter.GetLuaState().Run(data)) {
         LockedStreamFile locked_stream =
             io_handler.GetErrorStreamFileSP()->Lock();
         locked_stream << toString(std::move(error));
@@ -157,7 +157,7 @@ class IOHandlerLuaInterpreter : public IOHandlerDelegate,
 
 ScriptInterpreterLua::ScriptInterpreterLua(Debugger &debugger)
     : ScriptInterpreter(debugger, eScriptLanguageLua),
-      m_lua(std::make_unique<Lua>()) {}
+      m_lua_state(std::make_unique<LuaState>()) {}
 
 ScriptInterpreterLua::~ScriptInterpreterLua() = default;
 
@@ -192,14 +192,14 @@ bool ScriptInterpreterLua::ExecuteOneLine(llvm::StringRef 
command,
   ScriptInterpreterIORedirect &io_redirect = **io_redirect_or_error;
 
   if (llvm::Error e =
-          m_lua->ChangeIO(io_redirect.GetOutputFile()->GetStream(),
-                          io_redirect.GetErrorFile()->GetStream())) {
+          m_lua_state->ChangeIO(io_redirect.GetOutputFile()->GetStream(),
+                                io_redirect.GetErrorFile()->GetStream())) {
     result->AppendErrorWithFormatv("lua failed to redirect I/O: {0}\n",
                                    llvm::toString(std::move(e)));
     return false;
   }
 
-  if (llvm::Error e = m_lua->Run(command)) {
+  if (llvm::Error e = m_lua_state->Run(command)) {
     result->AppendErrorWithFormatv(
         "lua failed attempting to evaluate '{0}': {1}\n", command,
         llvm::toString(std::move(e)));
@@ -230,7 +230,7 @@ bool ScriptInterpreterLua::LoadScriptingModule(
     lldb_private::Status &error, StructuredData::ObjectSP *module_sp,
     FileSpec extra_search_dir, lldb::TargetSP loaded_into_target_sp) {
 
-  if (llvm::Error e = m_lua->LoadModule(filename)) {
+  if (llvm::Error e = m_lua_state->LoadModule(filename)) {
     error = Status::FromErrorStringWithFormatv(
         "lua failed to import '{0}': {1}\n", filename,
         llvm::toString(std::move(e)));
@@ -261,7 +261,7 @@ llvm::Error ScriptInterpreterLua::EnterSession(user_id_t 
debugger_id) {
       "lldb.process = lldb.target:GetProcess(); "
       "lldb.thread = lldb.process:GetSelectedThread(); "
       "lldb.frame = lldb.thread:GetSelectedFrame()";
-  return m_lua->Run(llvm::formatv(fmt_str, debugger_id).str());
+  return m_lua_state->Run(llvm::formatv(fmt_str, debugger_id).str());
 }
 
 llvm::Error ScriptInterpreterLua::LeaveSession() {
@@ -275,7 +275,7 @@ llvm::Error ScriptInterpreterLua::LeaveSession() {
                         "lldb.process = nil; "
                         "lldb.thread = nil; "
                         "lldb.frame = nil";
-  return m_lua->Run(str);
+  return m_lua_state->Run(str);
 }
 
 bool ScriptInterpreterLua::BreakpointCallbackFunction(
@@ -295,10 +295,10 @@ bool ScriptInterpreterLua::BreakpointCallbackFunction(
   Debugger &debugger = target->GetDebugger();
   ScriptInterpreterLua *lua_interpreter = static_cast<ScriptInterpreterLua *>(
       debugger.GetScriptInterpreter(true, eScriptLanguageLua));
-  Lua &lua = lua_interpreter->GetLua();
+  LuaState &lua_state = lua_interpreter->GetLuaState();
 
   CommandDataLua *bp_option_data = static_cast<CommandDataLua *>(baton);
-  llvm::Expected<bool> BoolOrErr = lua.CallBreakpointCallback(
+  llvm::Expected<bool> BoolOrErr = lua_state.CallBreakpointCallback(
       baton, stop_frame_sp, bp_loc_sp, bp_option_data->m_extra_args_sp);
   if (llvm::Error E = BoolOrErr.takeError()) {
     *debugger.GetAsyncErrorStream() << toString(std::move(E));
@@ -323,10 +323,10 @@ bool ScriptInterpreterLua::WatchpointCallbackFunction(
   Debugger &debugger = target->GetDebugger();
   ScriptInterpreterLua *lua_interpreter = static_cast<ScriptInterpreterLua *>(
       debugger.GetScriptInterpreter(true, eScriptLanguageLua));
-  Lua &lua = lua_interpreter->GetLua();
+  LuaState &lua_state = lua_interpreter->GetLuaState();
 
   llvm::Expected<bool> BoolOrErr =
-      lua.CallWatchpointCallback(baton, stop_frame_sp, wp_sp);
+      lua_state.CallWatchpointCallback(baton, stop_frame_sp, wp_sp);
   if (llvm::Error E = BoolOrErr.takeError()) {
     *debugger.GetAsyncErrorStream() << toString(std::move(E));
     return true;
@@ -372,7 +372,7 @@ Status ScriptInterpreterLua::RegisterBreakpointCallback(
     StructuredData::ObjectSP extra_args_sp) {
   auto data_up = std::make_unique<CommandDataLua>(extra_args_sp);
   llvm::Error err =
-      m_lua->RegisterBreakpointCallback(data_up.get(), command_body_text);
+      m_lua_state->RegisterBreakpointCallback(data_up.get(), 
command_body_text);
   if (err)
     return Status::FromError(std::move(err));
   auto baton_sp =
@@ -393,7 +393,7 @@ Status ScriptInterpreterLua::RegisterWatchpointCallback(
     StructuredData::ObjectSP extra_args_sp) {
   auto data_up = std::make_unique<WatchpointOptions::CommandData>();
   llvm::Error err =
-      m_lua->RegisterWatchpointCallback(data_up.get(), command_body_text);
+      m_lua_state->RegisterWatchpointCallback(data_up.get(), 
command_body_text);
   if (err)
     return Status::FromError(std::move(err));
   auto baton_sp =
@@ -412,4 +412,4 @@ llvm::StringRef 
ScriptInterpreterLua::GetPluginDescriptionStatic() {
   return "Lua script interpreter";
 }
 
-Lua &ScriptInterpreterLua::GetLua() { return *m_lua; }
+LuaState &ScriptInterpreterLua::GetLuaState() { return *m_lua_state; }

diff  --git a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h 
b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
index 7b879713fd3b1..311b90f281088 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Lua/ScriptInterpreterLua.h
@@ -18,7 +18,7 @@
 #include "lldb/lldb-enumerations.h"
 
 namespace lldb_private {
-class Lua;
+class LuaState;
 class ScriptInterpreterLua : public ScriptInterpreter {
 public:
   class CommandDataLua : public BreakpointOptions::CommandData {
@@ -75,7 +75,7 @@ class ScriptInterpreterLua : public ScriptInterpreter {
   // PluginInterface protocol
   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
 
-  Lua &GetLua();
+  LuaState &GetLuaState();
 
   llvm::Error EnterSession(lldb::user_id_t debugger_id);
   llvm::Error LeaveSession();
@@ -101,7 +101,7 @@ class ScriptInterpreterLua : public ScriptInterpreter {
       StructuredData::ObjectSP extra_args_sp) override;
 
 private:
-  std::unique_ptr<Lua> m_lua;
+  std::unique_ptr<LuaState> m_lua_state;
   bool m_session_is_active = false;
 
   Status RegisterBreakpointCallback(BreakpointOptions &bp_options,

diff  --git a/lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp 
b/lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
index 3b5836cfa8033..c73022b6f4b2d 100644
--- a/lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
+++ b/lldb/unittests/ScriptInterpreter/Lua/LuaTests.cpp
@@ -6,7 +6,7 @@
 //
 
//===----------------------------------------------------------------------===//
 
-#include "Plugins/ScriptInterpreter/Lua/Lua.h"
+#include "Plugins/ScriptInterpreter/Lua/LuaState.h"
 #include "Plugins/ScriptInterpreter/Lua/SWIGLuaBridge.h"
 #include "gtest/gtest.h"
 
@@ -29,14 +29,14 @@ 
lldb_private::lua::SWIGBridge::LLDBSwigLuaWatchpointCallbackFunction(
 }
 
 TEST(LuaTest, RunValid) {
-  Lua lua;
-  llvm::Error error = lua.Run("foo = 1");
+  LuaState lua_state;
+  llvm::Error error = lua_state.Run("foo = 1");
   EXPECT_FALSE(static_cast<bool>(error));
 }
 
 TEST(LuaTest, RunInvalid) {
-  Lua lua;
-  llvm::Error error = lua.Run("nil = foo");
+  LuaState lua_state;
+  llvm::Error error = lua_state.Run("nil = foo");
   EXPECT_TRUE(static_cast<bool>(error));
   EXPECT_EQ(llvm::toString(std::move(error)),
             "[string \"buffer\"]:1: unexpected symbol near 'nil'\n");


        
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to