From 0efb226c2f441fc25d837fdf360069703876b2dc Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 18 Dec 2021 23:38:16 +0100 Subject: [PATCH] patterns: Make std::env return an empty string and throw a warning if env var doesn't exist --- plugins/builtin/source/content/pl_builtin_functions.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/builtin/source/content/pl_builtin_functions.cpp b/plugins/builtin/source/content/pl_builtin_functions.cpp index b2ce6eef4..8c688fe5b 100644 --- a/plugins/builtin/source/content/pl_builtin_functions.cpp +++ b/plugins/builtin/source/content/pl_builtin_functions.cpp @@ -86,7 +86,13 @@ namespace hex::plugin::builtin { ContentRegistry::PatternLanguageFunctions::add(nsStd, "env", 1, [](Evaluator *ctx, auto params) -> std::optional { 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 ""; + } }); }