Message ID | 20221209141631.34536-1-a.heider@gmail.com |
---|---|
State | Accepted |
Headers | show |
Series | [uhttpd] ucode: respect all arguments passed to send() | expand |
On 09/12/2022 15:16, Andre Heider wrote: > Similar to ucode's print() this now prints any given values to stdout: > uhttpd.send(a, b, c, "\n"); > > Signed-off-by: Andre Heider <a.heider@gmail.com> Friendly ping! Any takers? > --- > ucode.c | 26 ++++++++++++++------------ > 1 file changed, 14 insertions(+), 12 deletions(-) > > diff --git a/ucode.c b/ucode.c > index aa5d5b4..bbb9b00 100644 > --- a/ucode.c > +++ b/ucode.c > @@ -115,20 +115,22 @@ uh_ucode_recv(uc_vm_t *vm, size_t nargs) > static uc_value_t * > uh_ucode_send(uc_vm_t *vm, size_t nargs) > { > - uc_value_t *val = uc_fn_arg(0); > - ssize_t len; > + uc_value_t *val; > + size_t arridx; > + ssize_t len = 0; > char *p; > > - if (ucv_type(val) == UC_STRING) { > - len = write(STDOUT_FILENO, ucv_string_get(val), ucv_string_length(val)); > - } > - else if (val != NULL) { > - p = ucv_to_string(vm, val); > - len = p ? write(STDOUT_FILENO, p, strlen(p)) : 0; > - free(p); > - } > - else { > - len = 0; > + for (arridx = 0; arridx < nargs; arridx++) { > + val = uc_fn_arg(arridx); > + > + if (ucv_type(val) == UC_STRING) { > + len += write(STDOUT_FILENO, ucv_string_get(val), ucv_string_length(val)); > + } > + else if (val != NULL) { > + p = ucv_to_string(vm, val); > + len += p ? write(STDOUT_FILENO, p, strlen(p)) : 0; > + free(p); > + } > } > > return ucv_int64_new(len);
diff --git a/ucode.c b/ucode.c index aa5d5b4..bbb9b00 100644 --- a/ucode.c +++ b/ucode.c @@ -115,20 +115,22 @@ uh_ucode_recv(uc_vm_t *vm, size_t nargs) static uc_value_t * uh_ucode_send(uc_vm_t *vm, size_t nargs) { - uc_value_t *val = uc_fn_arg(0); - ssize_t len; + uc_value_t *val; + size_t arridx; + ssize_t len = 0; char *p; - if (ucv_type(val) == UC_STRING) { - len = write(STDOUT_FILENO, ucv_string_get(val), ucv_string_length(val)); - } - else if (val != NULL) { - p = ucv_to_string(vm, val); - len = p ? write(STDOUT_FILENO, p, strlen(p)) : 0; - free(p); - } - else { - len = 0; + for (arridx = 0; arridx < nargs; arridx++) { + val = uc_fn_arg(arridx); + + if (ucv_type(val) == UC_STRING) { + len += write(STDOUT_FILENO, ucv_string_get(val), ucv_string_length(val)); + } + else if (val != NULL) { + p = ucv_to_string(vm, val); + len += p ? write(STDOUT_FILENO, p, strlen(p)) : 0; + free(p); + } } return ucv_int64_new(len);
Similar to ucode's print() this now prints any given values to stdout: uhttpd.send(a, b, c, "\n"); Signed-off-by: Andre Heider <a.heider@gmail.com> --- ucode.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)