forked from ground/ground
Add exists instruction
This commit is contained in:
27
src/main.cpp
27
src/main.cpp
@@ -73,7 +73,7 @@ enum class Instructions {
|
||||
Stdout, Stdin, Stdlnout,
|
||||
Add, Subtract, Multiply, Divide,
|
||||
Equal, Inequal, Greater, Lesser, Not,
|
||||
End, Set, Empty, Gettype,
|
||||
End, Set, Empty, Gettype, Exists,
|
||||
Setlist, Getlistat, Setlistat, Getlistsize, Listappend, Listprepend,
|
||||
Getstrcharat, Getstrsize,
|
||||
Stoi, Stod, Tostring,
|
||||
@@ -1655,6 +1655,30 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
case Instructions::Exists:
|
||||
if (l.args.size() < 2) {
|
||||
error("Could not find all arguments required for Exists inbuilt");
|
||||
}
|
||||
{
|
||||
Direct ref1;
|
||||
if (holds_alternative<Direct>(l.args[0])) {
|
||||
ref1 = get<Direct>(l.args[0]);
|
||||
} else {
|
||||
error("First argument of exists must be a direct reference");
|
||||
}
|
||||
|
||||
Direct ref2;
|
||||
if (holds_alternative<Direct>(l.args[1])) {
|
||||
ref2 = get<Direct>(l.args[1]);
|
||||
}
|
||||
|
||||
if (variables.find(ref1.varName) != variables.end()) {
|
||||
variables[ref2.varName].val = true;
|
||||
} else {
|
||||
variables[ref2.varName].val = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
/*
|
||||
fun instruction
|
||||
@@ -2113,6 +2137,7 @@ vector<Instruction> parser(vector<vector<string>> in) {
|
||||
else if (i == "end") newInst.inst = Instructions::End;
|
||||
else if (i == "set") newInst.inst = Instructions::Set;
|
||||
else if (i == "gettype") newInst.inst = Instructions::Gettype;
|
||||
else if (i == "exists") newInst.inst = Instructions::Exists;
|
||||
else if (i == "setlist") newInst.inst = Instructions::Setlist;
|
||||
else if (i == "setlistat") newInst.inst = Instructions::Setlistat;
|
||||
else if (i == "getlistat") newInst.inst = Instructions::Getlistat;
|
||||
|
Reference in New Issue
Block a user