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; return success;
} }
std::string cmd_incdec(bool type, std::vector<std::string> args) { std::string cmd_incdec(bool type, std::vector<std::string> args) {
bool asint = false;
//Check amount of arguments //Check amount of arguments
if (args.size() < 1 or args.size() > 2) { if (args.size() < 1 or args.size() > 3) {
return badarguments; return badarguments;
} }
// Get arguments // Get arguments
auto argsit = args.begin(); auto argsit = args.begin();
if (*argsit == "asint") {
asint = true;
argsit++;
}
std::string variablename = *argsit; std::string variablename = *argsit;
float incby; float incby;
if (args.size() == 2) { if (args.size() > 1) {
argsit++; argsit++;
incby = std::atof((*argsit).c_str()); incby = std::atof((*argsit).c_str());
} else { } else {
@ -257,7 +262,10 @@ std::string cmd_incdec(bool type, std::vector<std::string> args) {
currval += incby; currval += incby;
else else
currval -= incby; 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; return success;
} }