mirror of
https://gitlab.com/niansa/pilang3.git
synced 2025-03-06 20:49:20 +01:00
Added variable deletion
This commit is contained in:
parent
ba4f67517c
commit
361e6528c0
1 changed files with 13 additions and 0 deletions
|
@ -37,6 +37,18 @@ public:
|
||||||
(*env->globalScope)[std::get<std::string>(args[0].data)] = std::make_shared<Variable>(args[1]);
|
(*env->globalScope)[std::get<std::string>(args[0].data)] = std::make_shared<Variable>(args[1]);
|
||||||
return args[1];
|
return args[1];
|
||||||
}
|
}
|
||||||
|
static Variable del(SharedEnvironment env, Cmdargs& args) {
|
||||||
|
auto& scope = env->currScope();
|
||||||
|
auto res = scope.find(std::get<std::string>(args[0].data));
|
||||||
|
if (res == scope.end()) {
|
||||||
|
throw exceptions::NoSuchVariable();
|
||||||
|
}
|
||||||
|
scope.erase(res);
|
||||||
|
return Variable({
|
||||||
|
Variable::id_null,
|
||||||
|
0
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static Variable concat(SharedEnvironment, Cmdargs& args) {
|
static Variable concat(SharedEnvironment, Cmdargs& args) {
|
||||||
std::ostringstream fres;
|
std::ostringstream fres;
|
||||||
|
@ -61,6 +73,7 @@ public:
|
||||||
builtinCmds["="] = builtinCmds["set"] = {set, {Variable::id_string, Variable::id_any}, false};
|
builtinCmds["="] = builtinCmds["set"] = {set, {Variable::id_string, Variable::id_any}, false};
|
||||||
builtinCmds[":="] = builtinCmds["local"] = {local, {Variable::id_string, Variable::id_any}, false};
|
builtinCmds[":="] = builtinCmds["local"] = {local, {Variable::id_string, Variable::id_any}, false};
|
||||||
builtinCmds["!="] = builtinCmds["global"] = {global, {Variable::id_string, Variable::id_any}, false};
|
builtinCmds["!="] = builtinCmds["global"] = {global, {Variable::id_string, Variable::id_any}, false};
|
||||||
|
builtinCmds["delete"] = {del, {Variable::id_string}, false};
|
||||||
builtinCmds["concat"] = {concat, {}, true};
|
builtinCmds["concat"] = {concat, {}, true};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue