mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
feat(GlobalMethods): Add GetConfigValue method (#299)
Co-authored-by: iThorgrim <125808072+iThorgrim@users.noreply.github.com>
This commit is contained in:
@@ -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 },
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user