forked from ground/ground
Error function
This commit is contained in:
22
src/main.cpp
22
src/main.cpp
@@ -78,7 +78,8 @@ enum class Instructions {
|
||||
Getstrcharat, Getstrsize,
|
||||
Stoi, Stod, Tostring,
|
||||
Fun, Return, Endfun, Pusharg, Call, Local,
|
||||
Use, Extern
|
||||
Use, Extern,
|
||||
Error
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -636,6 +637,24 @@ Literal exec(vector<Instruction> in, bool executingFunction) {
|
||||
error("Argument of stdlnout must be a value (literal or a value reference)");
|
||||
}
|
||||
break;
|
||||
/*
|
||||
error instruction
|
||||
This instruction outputs a custom error message.
|
||||
*/
|
||||
|
||||
case Instructions::Error:
|
||||
if (l.args.size() < 1) {
|
||||
error("Could not find argument for Error inbuilt");
|
||||
}
|
||||
if (holds_alternative<Literal>(l.args[0])) {
|
||||
if (holds_alternative<string>(get<Literal>(l.args[0]).val)) {
|
||||
error(get<string>(get<Literal>(l.args[0]).val));
|
||||
} else {
|
||||
error("Argument of error must be a string");
|
||||
}
|
||||
} else {
|
||||
}
|
||||
break;
|
||||
/*
|
||||
set instruction
|
||||
This instruction sets a variable to a provided value.
|
||||
@@ -2232,6 +2251,7 @@ vector<Instruction> parser(vector<vector<string>> in) {
|
||||
else if (i == "stdin") newInst.inst = Instructions::Stdin;
|
||||
else if (i == "stdout") newInst.inst = Instructions::Stdout;
|
||||
else if (i == "stdlnout") newInst.inst = Instructions::Stdlnout;
|
||||
else if (i == "error") newInst.inst = Instructions::Error;
|
||||
else if (i == "jump") newInst.inst = Instructions::Jump;
|
||||
else if (i == "if") newInst.inst = Instructions::If;
|
||||
else if (i == "add") newInst.inst = Instructions::Add;
|
||||
|
||||
Reference in New Issue
Block a user