diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_function_call.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_function_call.hpp index b353032c8..a3a32ec38 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_function_call.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_function_call.hpp @@ -41,6 +41,9 @@ namespace hex::pl { } [[nodiscard]] std::unique_ptr evaluate(Evaluator *evaluator) const override { + auto startOffset = evaluator->dataOffset(); + ON_SCOPE_EXIT { evaluator->dataOffset() = startOffset; }; + std::vector evaluatedParams; for (auto ¶m : this->m_params) { const auto expression = param->evaluate(evaluator)->evaluate(evaluator); diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_function_definition.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_function_definition.hpp index c89748b75..cc275b786 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_function_definition.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_function_definition.hpp @@ -48,9 +48,11 @@ namespace hex::pl { evaluator->addCustomFunction(this->m_name, paramCount, [this](Evaluator *ctx, const std::vector ¶ms) -> std::optional { std::vector> variables; + auto startOffset = ctx->dataOffset(); ctx->pushScope(nullptr, variables); ON_SCOPE_EXIT { ctx->popScope(); + ctx->dataOffset() = startOffset; }; if (this->m_parameterPack.has_value()) {