Merge pull request #10525 from jig432/development

Added support for multiple arguments to a script subroutine.
This commit is contained in:
Theo Arends 2021-01-12 10:14:12 +01:00 committed by GitHub
commit 00b8f2aaed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4550,53 +4550,59 @@ int16_t Run_script_sub(const char *type, int8_t tlen, JsonParserObject *jo) {
if (*ctype=='#') { if (*ctype=='#') {
// check for parameter // check for parameter
ctype += tlen; ctype += tlen;
if (*ctype=='(' && *(lp+tlen)=='(') { char nxttok = '(';
float fparam; char *argptr = ctype+tlen;
numeric = 1;
glob_script_mem.glob_error = 0; lp += tlen;
GetNumericArgument((char*)ctype, OPER_EQU, &fparam, 0); do {
if (glob_script_mem.glob_error==1) { if (*ctype==nxttok && *lp==nxttok) {
// was string, not number float fparam;
numeric = 0; numeric = 1;
// get the string glob_script_mem.glob_error = 0;
GetStringArgument((char*)ctype + 1, OPER_EQU, cmpstr, 0); argptr = GetNumericArgument((char*)ctype + 1, OPER_EQU, &fparam, 0);
} if (glob_script_mem.glob_error==1) {
lp += tlen; // was string, not number
if (*lp=='(') { numeric = 0;
// fetch destination // get the string
lp++; argptr = GetStringArgument((char*)ctype + 1, OPER_EQU, cmpstr, 0);
lp = isvar(lp, &vtype, &ind, 0, 0, 0); }
if (vtype!=VAR_NV) { if (*lp==nxttok) {
// found variable as result // fetch destination
uint8_t index = glob_script_mem.type[ind.index].index; lp++;
if ((vtype&STYPE)==0) { lp = isvar(lp, &vtype, &ind, 0, 0, 0);
// numeric result if (vtype!=VAR_NV) {
dfvar = &glob_script_mem.fvars[index]; // found variable as result
if (numeric) { uint8_t index = glob_script_mem.type[ind.index].index;
*dfvar = fparam; if ((vtype&STYPE)==0) {
} else { // numeric result
// mismatch dfvar = &glob_script_mem.fvars[index];
*dfvar = CharToFloat(cmpstr); if (numeric) {
} *dfvar = fparam;
} else { } else {
// string result // mismatch
sindex = index; *dfvar = CharToFloat(cmpstr);
if (!numeric) { }
strlcpy(glob_script_mem.glob_snp + (sindex * glob_script_mem.max_ssize), cmpstr, glob_script_mem.max_ssize); } else {
} else { // string result
// mismatch sindex = index;
dtostrfd(fparam, 6, glob_script_mem.glob_snp + (sindex * glob_script_mem.max_ssize)); if (!numeric) {
} strlcpy(glob_script_mem.glob_snp + (sindex * glob_script_mem.max_ssize), cmpstr, glob_script_mem.max_ssize);
} else {
// mismatch
dtostrfd(fparam, 6, glob_script_mem.glob_snp + (sindex * glob_script_mem.max_ssize));
}
}
} }
} }
} else {
if (*ctype==nxttok || (*lp!=SCRIPT_EOL && *lp!='?')) {
// revert
section = 0;
}
} }
} else { nxttok = ' ';
lp += tlen; ctype = argptr;
if (*ctype=='(' || (*lp!=SCRIPT_EOL && *lp!='?')) { } while (*lp==' ' && (section == 1) );
// revert
section = 0;
}
}
} }
} }
} }