1
0
Fork 0
mirror of https://gitlab.com/niansa/pilang2.git synced 2025-03-06 20:49:22 +01:00

Implemented asint for inc/dec

This commit is contained in:
niansa 2020-05-28 10:58:20 +02:00
parent eb6e5c47d5
commit 8e61559f05

View file

@ -234,15 +234,20 @@ std::string cmd_append(std::vector<std::string> args) {
return success;
}
std::string cmd_incdec(bool type, std::vector<std::string> args) {
bool asint = false;
//Check amount of arguments
if (args.size() < 1 or args.size() > 2) {
if (args.size() < 1 or args.size() > 3) {
return badarguments;
}
// Get arguments
auto argsit = args.begin();
if (*argsit == "asint") {
asint = true;
argsit++;
}
std::string variablename = *argsit;
float incby;
if (args.size() == 2) {
if (args.size() > 1) {
argsit++;
incby = std::atof((*argsit).c_str());
} else {
@ -257,7 +262,10 @@ std::string cmd_incdec(bool type, std::vector<std::string> args) {
currval += incby;
else
currval -= incby;
variables[variablename] = std::to_string(currval);
if (!asint)
variables[variablename] = std::to_string(currval);
else
variables[variablename] = std::to_string((int)currval);
}
return success;
}