add: get/set var

This commit is contained in:
Eatswap 2022-12-12 23:25:31 +08:00
parent 8be5386075
commit 74ad9cfe2c
Signed by: Eatswap
GPG Key ID: BE661106A1F3FA0B
1 changed files with 12 additions and 0 deletions

View File

@ -27,6 +27,18 @@ public:
if (!this->parent) if (!this->parent)
delete this->funcs; delete this->funcs;
} }
std::shared_ptr<Value> 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> value) {
this->variables[name] = std::move(value);
}
}; };
} }