本文整理汇总了C++中duk_set_top函数的典型用法代码示例。如果您正苦于以下问题:C++ duk_set_top函数的具体用法?C++ duk_set_top怎么用?C++ duk_set_top使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了duk_set_top函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_4
static duk_ret_t test_4(duk_context *ctx, void *udata) {
(void) udata;
duk_set_top(ctx, 0);
duk_require_null(ctx, DUK_INVALID_INDEX);
printf("require DUK_INVALID_INDEX OK\n");
return 0;
}
示例2: test_3
static duk_ret_t test_3(duk_context *ctx, void *udata) {
(void) udata;
duk_set_top(ctx, 0);
duk_require_null(ctx, 0);
printf("require 0 OK\n");
return 0;
}
示例3: test_1
static duk_ret_t test_1(duk_context *ctx) {
duk_set_top(ctx, 0);
duk_error(ctx, DUK_ERR_RANGE_ERROR, "range error: %d", 123);
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
示例4: test_3
static duk_ret_t test_3(duk_context *ctx, void *udata) {
(void) udata;
duk_set_top(ctx, 0);
(void) duk_to_buffer(ctx, DUK_INVALID_INDEX, NULL);
printf("index DUK_INVALID_INDEX OK\n");
return 0;
}
示例5: test_2
static duk_ret_t test_2(duk_context *ctx, void *udata) {
(void) udata;
duk_set_top(ctx, 0);
duk_to_undefined(ctx, 3);
printf("index 3 OK\n");
return 0;
}
示例6: test_1
static duk_ret_t test_1(duk_context *ctx) {
duk_set_top(ctx, 0);
duk_push_string(ctx, "foo");
duk_push_string(ctx, "");
dump_string(duk_require_string(ctx, 0));
dump_string(duk_require_string(ctx, 1));
return 0;
}
示例7: test_2
static duk_ret_t test_2(duk_context *ctx, void *udata) {
(void) udata;
duk_set_top(ctx, 0);
(void) duk_to_buffer(ctx, 3, NULL);
printf("index 3 OK\n");
return 0;
}
示例8: test_2
static duk_ret_t test_2(duk_context *ctx, void *udata) {
(void) udata;
duk_set_top(ctx, 0);
duk_push_undefined(ctx);
duk_require_null(ctx, 0);
return 0;
}
示例9: test_3
static duk_ret_t test_3(duk_context *ctx, void *udata) {
(void) udata;
duk_set_top(ctx, 0);
duk_to_undefined(ctx, DUK_INVALID_INDEX);
printf("index DUK_INVALID_INDEX OK\n");
return 0;
}
示例10: test_1
static duk_ret_t test_1(duk_context *ctx) {
duk_set_top(ctx, 0);
duk_push_pointer(ctx, (void *) 0xdeadbeef);
duk_push_pointer(ctx, (void *) NULL);
printf("pointer: %p\n", duk_require_pointer(ctx, 0));
printf("pointer: %p\n", duk_require_pointer(ctx, 1));
return 0;
}
示例11: duk_bi_duktape_object_enc
DUK_INTERNAL duk_ret_t duk_bi_duktape_object_enc(duk_context *ctx) {
duk_hthread *thr = (duk_hthread *) ctx;
duk_hstring *h_str;
DUK_UNREF(thr);
/* Vararg function: must be careful to check/require arguments.
* The JSON helpers accept invalid indices and treat them like
* non-existent optional parameters.
*/
h_str = duk_require_hstring(ctx, 0);
duk_require_valid_index(ctx, 1);
if (h_str == DUK_HTHREAD_STRING_HEX(thr)) {
duk_set_top(ctx, 2);
duk_hex_encode(ctx, 1);
DUK_ASSERT_TOP(ctx, 2);
} else if (h_str == DUK_HTHREAD_STRING_BASE64(thr)) {
duk_set_top(ctx, 2);
duk_base64_encode(ctx, 1);
DUK_ASSERT_TOP(ctx, 2);
#ifdef DUK_USE_JX
} else if (h_str == DUK_HTHREAD_STRING_JX(thr)) {
duk_bi_json_stringify_helper(ctx,
1 /*idx_value*/,
2 /*idx_replacer*/,
3 /*idx_space*/,
DUK_JSON_FLAG_EXT_CUSTOM |
DUK_JSON_FLAG_ASCII_ONLY |
DUK_JSON_FLAG_AVOID_KEY_QUOTES /*flags*/);
#endif
#ifdef DUK_USE_JC
} else if (h_str == DUK_HTHREAD_STRING_JC(thr)) {
duk_bi_json_stringify_helper(ctx,
1 /*idx_value*/,
2 /*idx_replacer*/,
3 /*idx_space*/,
DUK_JSON_FLAG_EXT_COMPATIBLE |
DUK_JSON_FLAG_ASCII_ONLY /*flags*/);
#endif
} else {
return DUK_RET_TYPE_ERROR;
}
return 1;
}
示例12: test_2
static duk_ret_t test_2(duk_context *ctx) {
duk_set_top(ctx, 0);
duk_error(ctx, 1234567, "arbitrary error code");
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
示例13: test_encode
static duk_ret_t test_encode(duk_context *ctx) {
duk_set_top(ctx, 0);
duk_push_string(ctx, "foo");
duk_push_int(ctx, 123); /* dummy */
printf("hex encode: %s\n", duk_hex_encode(ctx, -2));
printf("top after: %ld\n", (long) duk_get_top(ctx)); /* value + dummy */
return 0;
}
示例14: prep
static void prep(duk_context *ctx) {
duk_set_top(ctx, 0);
print_stack(ctx);
duk_push_string(ctx, "foo");
duk_push_string(ctx, "bar");
duk_push_string(ctx, "quux");
print_stack(ctx);
}
示例15: test_1
int test_1(duk_context *ctx) {
int i, n;
char *buf;
duk_set_top(ctx, 0);
duk_push_undefined(ctx);
duk_push_null(ctx);
duk_push_true(ctx);
duk_push_false(ctx);
duk_push_nan(ctx);
duk_push_number(ctx, -INFINITY);
duk_push_number(ctx, +INFINITY);
duk_push_number(ctx, -0.0);
duk_push_number(ctx, +0.0);
duk_push_int(ctx, 123);
duk_push_string(ctx, "foo");
duk_push_lstring(ctx, "foo\0bar", 7); /* internal NULs are kept */
duk_push_object(ctx);
buf = (char *) duk_push_fixed_buffer(ctx, 0);
buf = (char *) duk_push_fixed_buffer(ctx, 16);
for (i = 0; i < 16; i++) {
buf[i] = i;
}
buf = (char *) duk_push_dynamic_buffer(ctx, 0);
buf = (char *) duk_push_dynamic_buffer(ctx, 16);
for (i = 0; i < 16; i++) {
buf[i] = i;
}
duk_push_pointer(ctx, (void *) NULL);
duk_push_pointer(ctx, (void *) 0xdeadbeef);
n = duk_get_top(ctx);
printf("top: %d\n", n);
for (i = 0; i < n; i++) {
int t1, t2;
void *ptr;
size_t sz;
duk_dup(ctx, i);
t1 = duk_get_type(ctx, -1);
sz = (size_t) 0xdeadbeef;
ptr = duk_to_buffer(ctx, -1, &sz);
t2 = duk_get_type(ctx, -1);
printf("index %d, type %d -> %d, ptr-is-NULL %d, size %u\n",
i, t1, t2, (sz == 0 ? -1 : (ptr == NULL ? 1 : 0)), (unsigned int) sz);
dump_buffer(ctx);
duk_pop(ctx);
/* just check that this doesn't break */
duk_dup(ctx, i);
ptr = duk_to_buffer(ctx, -1, NULL);
duk_pop(ctx);
}
return 0;
}