Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: missing configuration warning #2698

Merged
merged 13 commits into from
Jul 18, 2024
12 changes: 12 additions & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,17 @@ bool ConfigManager::reload() {
return result;
}

void ConfigManager::missingConfigWarning(const char* identifier) {
g_logger().warn("[ConfigManager::missingConfigWarning] Warning: Missing configuration for identifier: " + std::string(identifier));
lamonato29 marked this conversation as resolved.
Show resolved Hide resolved
}

std::string ConfigManager::loadStringConfig(lua_State* L, const ConfigKey_t &key, const char* identifier, const std::string &defaultValue) {
std::string value = defaultValue;
lua_getglobal(L, identifier);
if (lua_isstring(L, -1)) {
value = lua_tostring(L, -1);
} else {
missingConfigWarning(identifier);
}
configs[key] = value;
lua_pop(L, 1);
Expand All @@ -399,6 +405,8 @@ int32_t ConfigManager::loadIntConfig(lua_State* L, const ConfigKey_t &key, const
lua_getglobal(L, identifier);
if (lua_isnumber(L, -1)) {
value = static_cast<int32_t>(lua_tointeger(L, -1));
} else {
missingConfigWarning(identifier);
}
configs[key] = value;
lua_pop(L, 1);
Expand All @@ -410,6 +418,8 @@ bool ConfigManager::loadBoolConfig(lua_State* L, const ConfigKey_t &key, const c
lua_getglobal(L, identifier);
if (lua_isboolean(L, -1)) {
value = static_cast<bool>(lua_toboolean(L, -1));
} else {
missingConfigWarning(identifier);
}
configs[key] = value;
lua_pop(L, 1);
Expand All @@ -421,6 +431,8 @@ float ConfigManager::loadFloatConfig(lua_State* L, const ConfigKey_t &key, const
lua_getglobal(L, identifier);
if (lua_isnumber(L, -1)) {
value = static_cast<float>(lua_tonumber(L, -1));
} else {
missingConfigWarning(identifier);
}
configs[key] = value;
lua_pop(L, 1);
Expand Down
2 changes: 2 additions & 0 deletions src/config/configmanager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class ConfigManager {
bool load();
bool reload();

void missingConfigWarning(const char* identifier);

const std::string &setConfigFileLua(const std::string &what) {
configFileLua = { what };
return configFileLua;
Expand Down
Loading