From 74ad9cfe2c6824828ce84393e255dfe4adea4396 Mon Sep 17 00:00:00 2001 From: Eatswap Date: Mon, 12 Dec 2022 23:25:31 +0800 Subject: [PATCH] add: get/set var --- context.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/context.h b/context.h index 0c0868e..37479c5 100644 --- a/context.h +++ b/context.h @@ -27,6 +27,18 @@ public: if (!this->parent) delete this->funcs; } + + std::shared_ptr getVariable(const std::string& name) const { + if (this->variables.contains(name)) + return this->variables[name]; + if (this->parent) + return this->parent->getVariable(name); + return nullptr; + } + + void setVariable(const std::string& name, std::shared_ptr value) { + this->variables[name] = std::move(value); + } }; }