Skip to content

Commit 4fffa26

Browse files
committed
allow math in array length definition
1 parent 2ae28cc commit 4fffa26

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tasmota/tasmota_xdrv_driver/xdrv_10_scripter.ino

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,36 @@ uint32_t Script_Find_Vars(char *sp) {
949949
return (svars << 16) | numvars;
950950
}
951951

952+
// get integer with math
953+
int32_t get_math_intval(char *cp) {
954+
int32_t result = strtol(cp, &cp, 10);
955+
while (*cp) {
956+
while (*cp == ' ') cp++;
957+
if (*cp == SCRIPT_EOL) { break; }
958+
switch (*cp) {
959+
case '+':
960+
cp++;
961+
result += strtol(cp, &cp, 10);
962+
break;
963+
case '-':
964+
cp++;
965+
result -= strtol(cp, &cp, 10);
966+
break;
967+
case '*':
968+
cp++;
969+
result *= strtol(cp, &cp, 10);
970+
break;
971+
case '/':
972+
cp++;
973+
result /= strtol(cp, &cp, 10);
974+
break;
975+
}
976+
}
977+
return result;
978+
//return atoi(cp);
979+
}
980+
981+
952982
// allocates all variables and presets them
953983
int16_t Init_Scripter(void) {
954984
char *script;
@@ -1175,7 +1205,8 @@ char *script;
11751205
uint16_t flen = 1;
11761206
if (isdigit(*op)) {
11771207
// lenght define follows
1178-
flen = atoi(op);
1208+
//flen = atoi(op);
1209+
flen = get_math_intval(op);
11791210
if (flen > MAX_ARRAY_SIZE) {
11801211
// limit array size
11811212
flen = MAX_ARRAY_SIZE;

0 commit comments

Comments
 (0)