diff --git a/tests/tetests.cpp b/tests/tetests.cpp index b71a827..10e1963 100644 --- a/tests/tetests.cpp +++ b/tests/tetests.cpp @@ -2052,6 +2052,20 @@ TEST_CASE("Unknown symbol resolve funct pointer purge resolved 2", "[usr]") CHECK(parser.evaluate("id.temperature") == 53); } +TEST_CASE("Unknown symbol resolve lambda with capture", "[usr]") + { + std::string str("id.temperature < 51"); + double temperature = 49.0; + te_parser parser; + parser.set_unknown_symbol_resolver([&](std::string_view symbol) + { + return temperature += 1.0; + }, false); + CHECK(parser.compile(str)); // 50 + CHECK_FALSE(parser.evaluate(str)); // 51 + CHECK_FALSE(parser.evaluate(str)); // 52 + CHECK(parser.evaluate("id.temperature") == 53); + } TEST_CASE("Unknown symbol resolve 1 param purged", "[usr]") { diff --git a/tinyexpr.h b/tinyexpr.h index 2bb5fe2..d69e10c 100644 --- a/tinyexpr.h +++ b/tinyexpr.h @@ -67,6 +67,7 @@ #include #include #include +#include class te_expr; @@ -90,9 +91,9 @@ using te_confun6 = double (*)(const te_expr*, double, double, double, double, do using te_confun7 = double (*)(const te_expr*, double, double, double, double, double, double, double); // functions for unknown symbol resolution -using te_usr_noop = void (*)(); -using te_usr_fun0 = double (*)(std::string_view); -using te_usr_fun1 = double (*)(std::string_view, std::string&); +using te_usr_noop = std::function; +using te_usr_fun0 = std::function; +using te_usr_fun1 = std::function; using te_usr_variant_type = std::variant;