1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-12-24 18:36:03 +00:00

[script] add 2 new operators

- Str : Int ->  works like py's [Int:]
- Str - Int -> subtracts x amount of characters from the end of the string
This commit is contained in:
suchmememanyskill 2020-12-31 21:20:48 +01:00
parent 95d4f2bbeb
commit a39b3b2460
3 changed files with 33 additions and 1 deletions

View file

@ -344,6 +344,36 @@ Variable_t solveEquation(scriptCtx_t* ctx, lexarToken_t* tokens, u32 len, u8 sho
}
}
}
else if (res.varType == StringType && val.varType == IntType){
if (localOpToken == Minus){
u32 resLen = strlen(res.stringType);
if (resLen < val.integerType)
return ErrValue(ERRSYNTAX);
char *temp = malloc(resLen - val.integerType + 1);
memcpy(temp, res.stringType, resLen - val.integerType);
temp[resLen - val.integerType] = 0;
freeVariable(res);
res.stringType = temp;
res.free = 1;
}
ELIFT(Selector){
u32 resLen = strlen(res.stringType);
if (resLen < val.integerType)
return ErrValue(ERRSYNTAX);
char *temp = malloc(resLen - val.integerType + 1);
memcpy(temp, res.stringType + val.integerType, resLen - val.integerType);
temp[resLen - val.integerType] = 0;
freeVariable(res);
res.stringType = temp;
res.free = 1;
}
else
return ErrValue(ERRBADOPERATOR);
}
else
return ErrValue(ERRBADOPERATOR);
}
@ -351,7 +381,7 @@ Variable_t solveEquation(scriptCtx_t* ctx, lexarToken_t* tokens, u32 len, u8 sho
res = val;
}
}
else if (tokens[i].token >= Plus && tokens[i].token <= OR) {
else if (tokens[i].token >= Plus && tokens[i].token <= Selector) {
lastToken = tokens[i].token;
}
}

View file

@ -39,6 +39,7 @@ lexarTranslation_t lexarTranslations[] = {
{'<', Smaller},
{'>', Bigger},
{'!', Not},
{':', Selector},
{')', RBracket},
{']', RSBracket},
{'(', LBracket},

View file

@ -37,6 +37,7 @@ enum Tokens {
RSBracket,
AND,
OR,
Selector,
EquationSeperator,
};