feat(GlobalMethods): Add GetConfigValue method (#299)

Co-authored-by: iThorgrim <125808072+iThorgrim@users.noreply.github.com>
This commit is contained in:
Aldori
2025-09-02 15:44:31 -04:00
committed by GitHub
parent 059c20f3ac
commit 1c63eacec9
2 changed files with 44 additions and 0 deletions

View File

@@ -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 },

View File

@@ -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<const char*>(L, 1);
if (!key) return 0;
std::string val = sConfigMgr->GetOption<std::string>(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<uint32>(val);
if (intVal) {
Eluna::Push(L, *intVal);
return 1;
}
Eluna::Push(L, val);
return 1;
}
/**
* Returns emulator .conf RealmID
*