You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

54 lines
1.3 KiB

/*===
top: 10
index 0: string '(null)', length 0
index 0: string '(null)'
index 1: string '(null)', length 0
index 1: string '(null)'
index 2: string '(null)', length 0
index 2: string '(null)'
index 3: string '(null)', length 0
index 3: string '(null)'
index 4: string '', length 0
index 4: string ''
index 5: string 'foo', length 3
index 5: string 'foo'
index 6: string 'foo', length 7
index 6: string 'foo'
index 7: string 'ሴxyz', length 6
index 7: string 'ሴxyz'
index 8: string '(null)', length 0
index 8: string '(null)'
index 9: string '(null)', length 0
index 9: string '(null)'
===*/
void test(duk_context *ctx) {
int i, n;
duk_push_undefined(ctx);
duk_push_null(ctx);
duk_push_true(ctx);
duk_push_false(ctx);
duk_push_string(ctx, "");
duk_push_string(ctx, "foo");
duk_push_lstring(ctx, "foo\0bar", 7);
duk_push_string(ctx, "\xe1\x88\xb4xyz"); /* 4 chars, first char utf-8 encoded U+1234 */
duk_push_nan(ctx);
duk_push_object(ctx);
n = duk_get_top(ctx);
printf("top: %d\n", n);
for (i = 0; i < n; i++) {
const char *buf;
size_t len;
len = (size_t) 0xdeadbeef;
buf = duk_get_lstring(ctx, i, &len);
printf("index %d: string '%s', length %u\n", i, buf, (unsigned int) len);
buf = duk_get_lstring(ctx, i, NULL);
printf("index %d: string '%s'\n", i, buf);
}
}