|
|
@@ -4,7 +4,9 @@
|
|
|
#include "lumacs/completion_system.hpp" // Added for CompletionSystem access
|
|
|
#include "lumacs/plugin_manager.hpp" // Added for PluginManager access
|
|
|
#include "lumacs/buffer_manager.hpp" // Added for BufferManager::BufferInfo
|
|
|
-#include <iostream>
|
|
|
+#include "lumacs/logger.hpp"
|
|
|
+#include <spdlog/spdlog.h>
|
|
|
+#include <iostream> // Kept for now if needed by sol2 internals or other parts, but trying to remove direct usage
|
|
|
#include <fstream>
|
|
|
#include <filesystem> // For std::filesystem::path
|
|
|
|
|
|
@@ -72,16 +74,16 @@ void LuaApi::set_core(EditorCore& core) {
|
|
|
|
|
|
bool LuaApi::load_file(const std::filesystem::path& path) {
|
|
|
try {
|
|
|
- std::cerr << "[DEBUG] Loading Lua file: " << path << std::endl;
|
|
|
+ spdlog::debug("Loading Lua file: {}", path.string());
|
|
|
lua_.script_file(path.string());
|
|
|
- std::cerr << "[DEBUG] Lua file loaded successfully" << std::endl;
|
|
|
- std::cout << "Loaded Lua file: " << path << std::endl;
|
|
|
+ spdlog::debug("Lua file loaded successfully");
|
|
|
+ spdlog::info("Loaded Lua file: {}", path.string());
|
|
|
return true;
|
|
|
} catch (const sol::error& e) {
|
|
|
- std::cerr << "[ERROR] Lua error loading " << path << ": " << e.what() << std::endl;
|
|
|
+ spdlog::error("Lua error loading {}: {}", path.string(), e.what());
|
|
|
return false;
|
|
|
} catch (const std::exception& e) {
|
|
|
- std::cerr << "[ERROR] Exception loading " << path << ": " << e.what() << std::endl;
|
|
|
+ spdlog::error("Exception loading {}: {}", path.string(), e.what());
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
@@ -91,7 +93,7 @@ bool LuaApi::execute(std::string_view code) {
|
|
|
lua_.script(code);
|
|
|
return true;
|
|
|
} catch (const sol::error& e) {
|
|
|
- std::cerr << "Lua error: " << e.what() << std::endl;
|
|
|
+ spdlog::error("Lua error: {}", e.what());
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
@@ -110,17 +112,17 @@ bool LuaApi::load_init_file() {
|
|
|
|
|
|
for (const auto& path : search_paths) {
|
|
|
if (std::filesystem::exists(path)) {
|
|
|
- std::cout << "Found init file: " << path << std::endl;
|
|
|
+ spdlog::info("Found init file: {}", path.string());
|
|
|
return load_file(path);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- std::cout << "No init.lua found (searched: ./init.lua, ~/.config/lumacs/init.lua, ~/.lumacs/init.lua)" << std::endl;
|
|
|
+ spdlog::warn("No init.lua found (searched: ./init.lua, ~/.config/lumacs/init.lua, ~/.lumacs/init.lua)");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
void LuaApi::bind_key(std::string key, sol::function callback, std::string description) {
|
|
|
- std::cerr << "[DEBUG] Registering key binding: " << key << std::endl;
|
|
|
+ spdlog::debug("Registering key binding: {}", key);
|
|
|
|
|
|
// Create a unique command name for the Lua function
|
|
|
// This is a simple way; a more robust system might handle conflicts or namespaces
|
|
|
@@ -192,7 +194,7 @@ bool LuaApi::execute_key_binding(const std::string& key) {
|
|
|
it->second();
|
|
|
return true;
|
|
|
} catch (const sol::error& e) {
|
|
|
- std::cerr << "Lua error executing key binding '" << key << "': " << e.what() << "\n";
|
|
|
+ spdlog::error("Lua error executing key binding '{}': {}", key, e.what());
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
@@ -200,7 +202,7 @@ bool LuaApi::execute_key_binding(const std::string& key) {
|
|
|
// Manual C functions implementations
|
|
|
int LuaApi::get_active_buffer_line_count_lua() {
|
|
|
if (!core_ || !core_->active_window() || !core_->active_window()->buffer_ptr()) {
|
|
|
- std::cerr << "[DEBUG_MANUAL] get_active_buffer_line_count_lua: Core, active window or buffer is null!\n";
|
|
|
+ spdlog::warn("get_active_buffer_line_count_lua: Core, active window or buffer is null!");
|
|
|
return 0;
|
|
|
}
|
|
|
return static_cast<int>(core_->buffer().line_count());
|
|
|
@@ -208,7 +210,7 @@ int LuaApi::get_active_buffer_line_count_lua() {
|
|
|
|
|
|
void LuaApi::lua_editor_move_right() {
|
|
|
if (!core_) {
|
|
|
- std::cerr << "[DEBUG_MANUAL] lua_editor_move_right: Core is null!\n";
|
|
|
+ spdlog::warn("lua_editor_move_right: Core is null!");
|
|
|
return;
|
|
|
}
|
|
|
core_->move_right();
|
|
|
@@ -216,7 +218,7 @@ void LuaApi::lua_editor_move_right() {
|
|
|
|
|
|
void LuaApi::lua_editor_new_buffer(const std::string& name) {
|
|
|
if (!core_) {
|
|
|
- std::cerr << "[DEBUG_MANUAL] lua_editor_new_buffer: Core is null!\n";
|
|
|
+ spdlog::warn("lua_editor_new_buffer: Core is null!");
|
|
|
return;
|
|
|
}
|
|
|
core_->new_buffer(name);
|
|
|
@@ -224,7 +226,7 @@ void LuaApi::lua_editor_new_buffer(const std::string& name) {
|
|
|
|
|
|
sol::optional<std::string> LuaApi::lua_editor_get_buffer_by_name(const std::string& name) {
|
|
|
if (!core_) {
|
|
|
- std::cerr << "[DEBUG_MANUAL] lua_editor_get_buffer_by_name: Core is null!\n";
|
|
|
+ spdlog::warn("lua_editor_get_buffer_by_name: Core is null!");
|
|
|
return sol::nullopt;
|
|
|
}
|
|
|
if (auto buffer = core_->get_buffer_by_name(name)) {
|
|
|
@@ -235,7 +237,7 @@ sol::optional<std::string> LuaApi::lua_editor_get_buffer_by_name(const std::stri
|
|
|
|
|
|
void LuaApi::lua_editor_set_message(const std::string& message) {
|
|
|
if (!core_) {
|
|
|
- std::cerr << "[DEBUG_MANUAL] lua_editor_set_message: Core is null!\n";
|
|
|
+ spdlog::warn("lua_editor_set_message: Core is null!");
|
|
|
return;
|
|
|
}
|
|
|
core_->set_message(message);
|
|
|
@@ -243,7 +245,7 @@ void LuaApi::lua_editor_set_message(const std::string& message) {
|
|
|
|
|
|
void LuaApi::lua_config_set_string(const std::string& key, const std::string& value) {
|
|
|
if (!core_) {
|
|
|
- std::cerr << "[DEBUG_MANUAL] lua_config_set_string: Core is null!\n";
|
|
|
+ spdlog::warn("lua_config_set_string: Core is null!");
|
|
|
return;
|
|
|
}
|
|
|
core_->config().set(key, value);
|
|
|
@@ -251,7 +253,7 @@ void LuaApi::lua_config_set_string(const std::string& key, const std::string& va
|
|
|
|
|
|
std::string LuaApi::lua_config_get_string(const std::string& key, const std::string& default_val) {
|
|
|
if (!core_) {
|
|
|
- std::cerr << "[DEBUG_MANUAL] lua_config_get_string: Core is null!\n";
|
|
|
+ spdlog::warn("lua_config_get_string: Core is null!");
|
|
|
return default_val;
|
|
|
}
|
|
|
return core_->config().get<std::string>(key, default_val);
|
|
|
@@ -259,7 +261,7 @@ std::string LuaApi::lua_config_get_string(const std::string& key, const std::str
|
|
|
|
|
|
void LuaApi::lua_config_set_bool(const std::string& key, bool value) {
|
|
|
if (!core_) {
|
|
|
- std::cerr << "[DEBUG_MANUAL] lua_config_set_bool: Core is null!\n";
|
|
|
+ spdlog::warn("lua_config_set_bool: Core is null!");
|
|
|
return;
|
|
|
}
|
|
|
core_->config().set(key, value);
|
|
|
@@ -267,7 +269,7 @@ void LuaApi::lua_config_set_bool(const std::string& key, bool value) {
|
|
|
|
|
|
bool LuaApi::lua_config_get_bool(const std::string& key, bool default_val) {
|
|
|
if (!core_) {
|
|
|
- std::cerr << "[DEBUG_MANUAL] lua_config_get_bool: Core is null!\n";
|
|
|
+ spdlog::warn("lua_config_get_bool: Core is null!");
|
|
|
return default_val;
|
|
|
}
|
|
|
return core_->config().get<bool>(key, default_val);
|
|
|
@@ -275,7 +277,7 @@ bool LuaApi::lua_config_get_bool(const std::string& key, bool default_val) {
|
|
|
|
|
|
void LuaApi::lua_config_set_int(const std::string& key, int value) {
|
|
|
if (!core_) {
|
|
|
- std::cerr << "[DEBUG_MANUAL] lua_config_set_int: Core is null!\n";
|
|
|
+ spdlog::warn("lua_config_set_int: Core is null!");
|
|
|
return;
|
|
|
}
|
|
|
core_->config().set(key, value);
|
|
|
@@ -283,7 +285,7 @@ void LuaApi::lua_config_set_int(const std::string& key, int value) {
|
|
|
|
|
|
int LuaApi::lua_config_get_int(const std::string& key, int default_val) {
|
|
|
if (!core_) {
|
|
|
- std::cerr << "[DEBUG_MANUAL] lua_config_get_int: Core is null!\n";
|
|
|
+ spdlog::warn("lua_config_get_int: Core is null!");
|
|
|
return default_val;
|
|
|
}
|
|
|
return core_->config().get<int>(key, default_val);
|
|
|
@@ -326,7 +328,7 @@ void LuaApi::setup_api() {
|
|
|
|
|
|
// Initialize MobDebug if enabled
|
|
|
if (core_->config().get<bool>("debug_lua", false)) { // Corrected Config access
|
|
|
- std::cerr << "[DEBUG] Lua debugging enabled." << std::endl;
|
|
|
+ spdlog::debug("Lua debugging enabled.");
|
|
|
std::string debug_host = core_->config().get<std::string>("debug_host", "127.0.0.1"); // Corrected Config access
|
|
|
int debug_port = core_->config().get<int>("debug_port", 8171); // Corrected Config access
|
|
|
|
|
|
@@ -335,19 +337,19 @@ void LuaApi::setup_api() {
|
|
|
// Explicitly require 'mobdebug' module
|
|
|
sol::optional<sol::table> mobdebug = lua_["require"]("mobdebug");
|
|
|
if (mobdebug) {
|
|
|
- std::cerr << "[DEBUG] MobDebug module loaded." << std::endl;
|
|
|
+ spdlog::debug("MobDebug module loaded.");
|
|
|
sol::function mobdebug_start = mobdebug.value()["start"];
|
|
|
if (mobdebug_start.valid()) {
|
|
|
mobdebug_start(debug_host, debug_port);
|
|
|
- std::cerr << "[INFO] MobDebug started on " << debug_host << ":" << debug_port << std::endl;
|
|
|
+ spdlog::info("MobDebug started on {}:{}", debug_host, debug_port);
|
|
|
} else {
|
|
|
- std::cerr << "[ERROR] MobDebug.start function not found." << std::endl;
|
|
|
+ spdlog::error("MobDebug.start function not found.");
|
|
|
}
|
|
|
} else {
|
|
|
- std::cerr << "[ERROR] Failed to load MobDebug module. Is LuaRocks installed and configured?" << std::endl;
|
|
|
+ spdlog::error("Failed to load MobDebug module. Is LuaRocks installed and configured?");
|
|
|
}
|
|
|
} catch (const sol::error& e) {
|
|
|
- std::cerr << "[ERROR] Lua error during MobDebug initialization: " << e.what() << std::endl;
|
|
|
+ spdlog::error("Lua error during MobDebug initialization: {}", e.what());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -761,10 +763,12 @@ void LuaApi::register_functions() {
|
|
|
|
|
|
// Print function that goes to stderr (since stdout is used by TUI)
|
|
|
lua_["print"] = [](sol::variadic_args args) {
|
|
|
+ std::string message;
|
|
|
for (auto arg : args) {
|
|
|
- std::cerr << lua_tostring(arg.lua_state(), arg.stack_index()) << "\t";
|
|
|
+ message += lua_tostring(arg.lua_state(), arg.stack_index());
|
|
|
+ message += "\t";
|
|
|
}
|
|
|
- std::cerr << std::endl;
|
|
|
+ spdlog::info("[Lua] {}", message);
|
|
|
};
|
|
|
|
|
|
// Command system functions
|