summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Fietkau2025-07-22 15:39:21 +0000
committerFelix Fietkau2025-07-22 15:39:21 +0000
commit98683a94bcdd0c9201b52344aee9f4b37bcc53ef (patch)
tree69a3a0232a840ff1538ba120579c9a5fa55861d2
parentf207d37a1055e2a5a453ed7dc119680cb017227b (diff)
downloadudebug-98683a94bcdd0c9201b52344aee9f4b37bcc53ef.tar.gz
ucode: support appending array data, similar to socket.send()
Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--lib-ucode.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/lib-ucode.c b/lib-ucode.c
index 9199f99..2e63c0b 100644
--- a/lib-ucode.c
+++ b/lib-ucode.c
@@ -585,23 +585,46 @@ uc_udebug_wbuf_close(uc_vm_t *vm, size_t nargs)
}
static void
-uc_udebug_wbuf_add_string(struct udebug_buf *buf, uc_value_t *val)
+uc_udebug_wbuf_append(uc_vm_t *vm, struct udebug_buf *buf, uc_value_t *val)
{
- udebug_entry_init(buf);
- udebug_entry_append(buf, ucv_string_get(val), ucv_string_length(val));
- udebug_entry_add(buf);
+ struct printbuf *pb;
+ size_t len;
+
+ if (!val)
+ return;
+
+ switch (ucv_type(val)) {
+ case UC_STRING:
+ udebug_entry_append(buf, ucv_string_get(val), ucv_string_length(val));
+ break;
+ case UC_ARRAY:
+ len = ucv_array_length(val);
+ for (size_t i = 0; i < len; i++)
+ uc_udebug_wbuf_append(vm, buf, ucv_array_get(val, i));
+ break;
+ default:
+ pb = xprintbuf_new();
+ ucv_to_stringbuf(vm, pb, val, false);
+ udebug_entry_append(buf, pb->buf, pb->bpos);
+ printbuf_free(pb);
+ break;
+ }
}
+
+
static uc_value_t *
uc_udebug_wbuf_add(uc_vm_t *vm, size_t nargs)
{
struct udebug_buf *buf = uc_fn_thisval("udebug.wbuf");
uc_value_t *arg = uc_fn_arg(0);
- if (!buf || ucv_type(arg) != UC_STRING)
+ if (!buf || !arg)
return NULL;
- uc_udebug_wbuf_add_string(buf, arg);
+ udebug_entry_init(buf);
+ uc_udebug_wbuf_append(vm, buf, arg);
+ udebug_entry_add(buf);
return ucv_boolean_new(true);
}