patterns: Make std::env return an empty string and throw a warning if env var doesn't exist

This commit is contained in:
WerWolv 2021-12-18 23:38:16 +01:00
parent ea92e17ca0
commit 0efb226c2f
1 changed files with 7 additions and 1 deletions

View File

@ -86,7 +86,13 @@ namespace hex::plugin::builtin {
ContentRegistry::PatternLanguageFunctions::add(nsStd, "env", 1, [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> { ContentRegistry::PatternLanguageFunctions::add(nsStd, "env", 1, [](Evaluator *ctx, auto params) -> std::optional<Token::Literal> {
auto name = Token::literalToString(params[0], false); auto name = Token::literalToString(params[0], false);
return ctx->getEnvVariable(name); auto env = ctx->getEnvVariable(name);
if (env)
return env;
else {
ctx->getConsole().log(LogConsole::Level::Warning, hex::format("environment variable '{}' does not exist", name));
return "";
}
}); });
} }