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


C++ duk_push_int函数代码示例

本文整理汇总了C++中duk_push_int函数的典型用法代码示例。如果您正苦于以下问题:C++ duk_push_int函数的具体用法?C++ duk_push_int怎么用?C++ duk_push_int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了duk_push_int函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_1

/* demonstrate how pushing too many elements causes an error */
static duk_ret_t test_1(duk_context *ctx, void *udata) {
	int i;

	(void) udata;

	for (i = 0; i < 1000; i++) {
		duk_push_int(ctx, 123);
	}

	printf("final top: %ld\n", (long) duk_get_top(ctx));
	return 0;
}
开发者ID:eliteYang,项目名称:duktape-js-cpp,代码行数:13,代码来源:test-check-require-stack-top.c

示例2: test_delprop_c

/* duk_del_prop(), non-configurable virtual property of a plain string.
 * Same behavior when called inside/outside of a Duktape/C activation.
 */
static duk_ret_t test_delprop_c(duk_context *ctx) {
	duk_ret_t rc;

	prep(ctx);

	duk_push_int(ctx, 5);
	rc = duk_del_prop(ctx, 2);
	printf("delete 'test_string'[5] -> rc=%d\n", (int) rc);

	printf("final top: %ld\n", (long) duk_get_top(ctx));
	return 0;
}
开发者ID:jmptrader,项目名称:duktape,代码行数:15,代码来源:test-del-prop.c

示例3: sys1_fstat

static int sys1_fstat(duk_context *ctx)
{
	int fd = duk_to_int(ctx, 0);
	struct stat stat;
	int rc;
	
	rc = fstat(fd, &stat);
	sys1_push_stat(ctx, &stat);
	duk_push_int(ctx, rc);
	duk_put_prop_string(ctx, -2, "rc");
	return 1;
}
开发者ID:jelaas,项目名称:sysjs,代码行数:12,代码来源:sys1.c

示例4: test

void test(duk_context *ctx) {
	duk_idx_t idx;

	duk_push_int(ctx, 123);
	duk_push_int(ctx, 234);
	duk_push_int(ctx, 345);

	for (idx = -5; idx <= 5; idx++) {
		printf("top=%ld, idx=%ld, duk_is_valid_index -> %d\n",
		       (long) duk_get_top(ctx), (long) idx,
		       (int) duk_is_valid_index(ctx, idx));
	}

	for (idx = -5; idx <= 5; idx++) {
		duk_push_int(ctx, idx);
		duk_safe_call(ctx, req_valid_idx, 1, 1);
		printf("idx=%ld, duk_require_valid_index -> %s\n",
		       (long) idx, duk_to_string(ctx, -1));
		duk_pop(ctx);
	}
}
开发者ID:OakLabsInc,项目名称:duktape,代码行数:21,代码来源:test-validate-index.c

示例5: test_1c

/* duk_del_prop(), non-configurable virtual property of a plain string,
 * called from inside a Duktape/C context.
*/
int test_1c(duk_context *ctx) {
	int rc;

	prep(ctx);

	duk_push_int(ctx, 5);
	rc = duk_del_prop(ctx, 2);
	printf("delete 'test_string'[5] -> rc=%d\n", rc);

	printf("final top: %d\n", duk_get_top(ctx));
	return 0;
}
开发者ID:BpLife,项目名称:duktape,代码行数:15,代码来源:test-del-prop.c

示例6: sys1_lstat

static int sys1_lstat(duk_context *ctx)
{
	const char *path = duk_to_string(ctx, 0);
	struct stat stat;
	int rc;
	
	rc = lstat(path, &stat);
	sys1_push_stat(ctx, &stat);
	duk_push_int(ctx, rc);
	duk_put_prop_string(ctx, -2, "rc");
	return 1;
}
开发者ID:jelaas,项目名称:sysjs,代码行数:12,代码来源:sys1.c

示例7: sys1_lseek

static int sys1_lseek(duk_context *ctx)
{
	int fd = duk_to_int(ctx, 0);
	off_t offset = duk_to_int(ctx, 1);
	int whence = duk_to_int(ctx, 2);
	off_t rc;

	rc = lseek(fd, offset, whence);

	duk_push_int(ctx, rc);
	return 1;
}
开发者ID:jelaas,项目名称:sysjs,代码行数:12,代码来源:sys1.c

示例8: test_delprop_a_safecall

/* duk_del_prop(), success cases */
static duk_ret_t test_delprop_a_safecall(duk_context *ctx, void *udata) {
	duk_ret_t rc;

	(void) udata;

	prep(ctx);

	/* existing, configurable */
	duk_push_string(ctx, "foo");
	rc = duk_del_prop(ctx, 0);
	printf("delete obj.foo -> rc=%d\n", (int) rc);

	/* nonexistent */
	duk_push_string(ctx, "nonexistent");
	rc = duk_del_prop(ctx, 0);
	printf("delete obj.nonexistent -> rc=%d\n", (int) rc);

	/* nonexistent */
	duk_push_int(ctx, 123);
	rc = duk_del_prop(ctx, 0);
	printf("delete obj[123] -> rc=%d\n", (int) rc);

	/* nonexistent, array */
	duk_push_string(ctx, "nonexistent");
	rc = duk_del_prop(ctx, 1);
	printf("delete arr.nonexistent -> rc=%d\n", (int) rc);

	/* existing, configurable, array */
	duk_push_int(ctx, 2);
	rc = duk_del_prop(ctx, 1);
	printf("delete arr[2] -> rc=%d\n", (int) rc);

	duk_json_encode(ctx, 0);
	printf("final object: %s\n", duk_to_string(ctx, 0));
	duk_json_encode(ctx, 1);
	printf("final array: %s\n", duk_to_string(ctx, 1));

	printf("final top: %ld\n", (long) duk_get_top(ctx));
	return 0;
}
开发者ID:jmptrader,项目名称:duktape,代码行数:41,代码来源:test-del-prop.c

示例9: test_1

static duk_ret_t test_1(duk_context *ctx) {
	duk_idx_t i, n;

	duk_set_top(ctx, 0);
	duk_push_undefined(ctx);
	duk_push_null(ctx);
	duk_push_true(ctx);
	duk_push_false(ctx);
	duk_push_int(ctx, 0);
	duk_push_int(ctx, 1);
	duk_push_nan(ctx);
	duk_push_number(ctx, INFINITY);
	duk_push_string(ctx, "");
	duk_push_string(ctx, "foo");
	duk_push_object(ctx);
	duk_push_number(ctx, 123.456);
	duk_to_object(ctx, -1);  /* Number(123.456) */
	duk_push_thread(ctx);
	duk_push_fixed_buffer(ctx, 0);
	duk_push_fixed_buffer(ctx, 1024);
	duk_push_dynamic_buffer(ctx, 0);
	duk_push_dynamic_buffer(ctx, 1024);
	duk_push_pointer(ctx, (void *) NULL);
	duk_push_pointer(ctx, (void *) 0xdeadbeef);

	n = duk_get_top(ctx);
	printf("top: %ld\n", (long) n);
	for (i = 0; i < n; i++) {
		duk_int_t t1, t2;

		t1 = duk_get_type(ctx, i);
		duk_to_primitive(ctx, i, DUK_HINT_NONE);
		t2 = duk_get_type(ctx, i);

		printf("index %ld, ToString(result): '%s', type: %ld -> %ld\n",
		       (long) i, duk_to_string(ctx, i), (long) t1, (long) t2);
	}

	return 0;
}
开发者ID:OakLabsInc,项目名称:duktape,代码行数:40,代码来源:test-to-primitive.c

示例10: sys1_write

static int sys1_write(duk_context *ctx)
{
	int fd = duk_to_int(ctx, 0);
	size_t bufsize;
	void *buf = duk_to_buffer(ctx, 1, &bufsize);
	int len = duk_to_int(ctx, 2);
	ssize_t rc;
	
	rc = write(fd, buf, len);

	duk_push_int(ctx, rc);
	return 1;
}
开发者ID:jelaas,项目名称:sysjs,代码行数:13,代码来源:sys1.c

示例11: test_putprop

static duk_ret_t test_putprop(duk_context *ctx, void *udata) {
	(void) udata;

	prep(ctx);

	/* Property exists, own property */
	duk_push_int(ctx, 1001);
	duk_put_prop_string(ctx, 0, "foo");
	printf("putprop foo done\n");

	/* Property exists, inherited property */
	duk_push_int(ctx, 1002);
	duk_put_prop_string(ctx, 0, "bar");
	printf("putprop bar done\n");

	/* Property doesn't exist, terminate with error */
	duk_push_int(ctx, 1003);
	duk_put_prop_string(ctx, 0, "quux");
	printf("putprop quux done\n");

	return 0;
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:22,代码来源:test-dev-prototype-loop.c

示例12: js_RawFile_get_position

static duk_ret_t
js_RawFile_get_position(duk_context* ctx)
{
	FILE* file;

	duk_push_this(ctx);
	file = duk_require_sphere_obj(ctx, -1, "RawFile");
	duk_pop(ctx);
	if (file == NULL)
		duk_error_ni(ctx, -1, DUK_ERR_ERROR, "RawFile:position - File has been closed");
	duk_push_int(ctx, ftell(file));
	return 1;
}
开发者ID:caivega,项目名称:minisphere,代码行数:13,代码来源:rawfile.c

示例13: mn_ref_setup

/*
 * Create a global array refs in the heap stash.
 */
void
mn_ref_setup(duk_context *ctx) {
	duk_push_heap_stash(ctx);

	/* Create a new array with one `0` at index `0`. */
	duk_push_array(ctx);
	duk_push_int(ctx, 0);
	duk_put_prop_index(ctx, -2, 0);
	/* Store it as "refs" in the heap stash */
	duk_put_prop_string(ctx, -2, "refs");

	duk_pop(ctx);
}
开发者ID:hypoalex,项目名称:mininode,代码行数:16,代码来源:ref.c

示例14: js_Font_getStringWidth

static duk_ret_t
js_Font_getStringWidth(duk_context* ctx)
{
	const char* text = duk_to_string(ctx, 0);
	
	font_t* font;

	duk_push_this(ctx);
	font = duk_require_sphere_obj(ctx, -1, "Font");
	duk_pop(ctx);
	duk_push_int(ctx, get_text_width(font, text));
	return 1;
}
开发者ID:svaarala,项目名称:minisphere,代码行数:13,代码来源:font.c

示例15: js_Font_getStringHeight

static duk_ret_t
js_Font_getStringHeight(duk_context* ctx)
{
	const char* text = duk_to_string(ctx, 0);
	int width = duk_require_int(ctx, 1);
	
	font_t* font;
	int     num_lines;

	duk_push_this(ctx);
	font = duk_require_sphere_obj(ctx, -1, "Font");
	duk_pop(ctx);
	duk_push_c_function(ctx, js_Font_wordWrapString, DUK_VARARGS);
	duk_push_this(ctx);
	duk_push_string(ctx, text);
	duk_push_int(ctx, width);
	duk_call_method(ctx, 2);
	duk_get_prop_string(ctx, -1, "length"); num_lines = duk_get_int(ctx, -1); duk_pop(ctx);
	duk_pop(ctx);
	duk_push_int(ctx, get_font_line_height(font) * num_lines);
	return 1;
}
开发者ID:svaarala,项目名称:minisphere,代码行数:22,代码来源:font.c


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