From 1c63eacec940c7494b33710dc3adfda2d846160e Mon Sep 17 00:00:00 2001 From: Aldori Date: Tue, 2 Sep 2025 15:44:31 -0400 Subject: [PATCH] feat(GlobalMethods): Add GetConfigValue method (#299) Co-authored-by: iThorgrim <125808072+iThorgrim@users.noreply.github.com> --- src/LuaEngine/LuaFunctions.cpp | 1 + src/LuaEngine/methods/GlobalMethods.h | 43 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/LuaEngine/LuaFunctions.cpp b/src/LuaEngine/LuaFunctions.cpp index f5f3359..d10201d 100644 --- a/src/LuaEngine/LuaFunctions.cpp +++ b/src/LuaEngine/LuaFunctions.cpp @@ -93,6 +93,7 @@ luaL_Reg GlobalMethods[] = // Getters { "GetLuaEngine", &LuaGlobalFunctions::GetLuaEngine }, { "GetCoreName", &LuaGlobalFunctions::GetCoreName }, + { "GetConfigValue", &LuaGlobalFunctions::GetConfigValue }, { "GetRealmID", &LuaGlobalFunctions::GetRealmID }, { "GetCoreVersion", &LuaGlobalFunctions::GetCoreVersion }, { "GetCoreExpansion", &LuaGlobalFunctions::GetCoreExpansion }, diff --git a/src/LuaEngine/methods/GlobalMethods.h b/src/LuaEngine/methods/GlobalMethods.h index eb3d3e0..b9491a5 100644 --- a/src/LuaEngine/methods/GlobalMethods.h +++ b/src/LuaEngine/methods/GlobalMethods.h @@ -55,6 +55,49 @@ namespace LuaGlobalFunctions return 1; } + /** + * Returns config value as a string. + * + * @param string name : name of the value + * @return string value + */ + int GetConfigValue(lua_State* L) + { + const char* key = Eluna::CHECKVAL(L, 1); + if (!key) return 0; + + std::string val = sConfigMgr->GetOption(key, "", false); + + if (val.empty()) + { + Eluna::Push(L, val); + return 1; + } + + std::string lower = val; + std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower); + + if (lower == "true") + { + Eluna::Push(L, true); + return 1; + } + else if (lower == "false") + { + Eluna::Push(L, false); + return 1; + } + + auto intVal = Acore::StringTo(val); + if (intVal) { + Eluna::Push(L, *intVal); + return 1; + } + + Eluna::Push(L, val); + return 1; + } + /** * Returns emulator .conf RealmID *