当前位置: 首页>>代码示例>>C++>>正文


C++ duk_set_top函数代码示例

本文整理汇总了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;
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:8,代码来源:test-require-null.c

示例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;
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:8,代码来源:test-require-null.c

示例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;
}
开发者ID:BrandonTheHamm,项目名称:duktape,代码行数:8,代码来源:test-error.c

示例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;
}
开发者ID:magul,项目名称:duktape,代码行数:8,代码来源:test-to-buffer.c

示例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;
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:8,代码来源:test-to-undefined.c

示例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;
}
开发者ID:CarterTsai,项目名称:duktape,代码行数:8,代码来源:test-require-string.c

示例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;
}
开发者ID:magul,项目名称:duktape,代码行数:8,代码来源:test-to-buffer.c

示例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;
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:8,代码来源:test-require-null.c

示例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;
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:8,代码来源:test-to-undefined.c

示例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;
}
开发者ID:OakLabsInc,项目名称:duktape,代码行数:8,代码来源:test-require-pointer.c

示例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;
}
开发者ID:BaroboRobotics,项目名称:civetweb,代码行数:46,代码来源:duk_bi_duktape.c

示例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;
}
开发者ID:BrandonTheHamm,项目名称:duktape,代码行数:8,代码来源:test-error.c

示例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;
}
开发者ID:OakLabsInc,项目名称:duktape,代码行数:8,代码来源:test-hex.c

示例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);
}
开发者ID:OakLabsInc,项目名称:duktape,代码行数:8,代码来源:test-get-set-top.c

示例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;
}
开发者ID:BpLife,项目名称:duktape,代码行数:58,代码来源:test-to-buffer.c


注:本文中的duk_set_top函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。