Skip to content

Commit

Permalink
add config missing warning
Browse files Browse the repository at this point in the history
  • Loading branch information
lamonato29 committed Jun 18, 2024
1 parent 4af5b2d commit b800f9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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));
}

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 @@ -25,6 +25,8 @@ class ConfigManager {

bool load();
bool reload();

void missingConfigWarning(const char* identifier);

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

0 comments on commit b800f9d

Please sign in to comment.