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


C++ duk_get_top函数代码示例

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


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

示例1: es_sqlite_query

static int
es_sqlite_query(duk_context *ctx)
{
    int argc = duk_get_top(ctx);
    if(argc < 2)
        return DUK_RET_TYPE_ERROR;

    es_sqlite_t *es = es_resource_get(ctx, 0, &es_resource_sqlite);
    const char *query = duk_safe_to_string(ctx, 1);

    if(es->es_stmt) {
        sqlite3_finalize(es->es_stmt);
        es->es_stmt = NULL;
    }

    int rc = db_prepare(es->es_db, &es->es_stmt, query);

    if(rc != SQLITE_OK) {

        if(es->es_transaction && rc == SQLITE_LOCKED)
            duk_error(ctx, ST_ERROR_SQLITE_BASE | rc , "Deadlock");

        duk_error(ctx, ST_ERROR_SQLITE_BASE | rc,
                  "Sqlite error 0x%x -- %s",
                  rc, sqlite3_errmsg(es->es_db));
    }

    sqlite3_stmt *stmt = es->es_stmt;

    for(int i = 2; i < argc; i++) {
        int sqlite_arg = i - 1;

        if(duk_is_null_or_undefined(ctx, i)) {
            sqlite3_bind_null(stmt, sqlite_arg);
        } else if(duk_is_number(ctx, i)) {
            sqlite3_bind_double(stmt, sqlite_arg, duk_get_number(ctx, i));
        } else if(duk_is_boolean(ctx, i)) {
            sqlite3_bind_int(stmt, sqlite_arg, duk_get_boolean(ctx, i));
        } else {
            sqlite3_bind_text(stmt, sqlite_arg, duk_safe_to_string(ctx, i),
                              -1, SQLITE_STATIC);
        }
    }

    es_sqlite_stmt_step(ctx, es);
    return 0;
}
开发者ID:bguerreiro,项目名称:movian,代码行数:47,代码来源:es_sqlite.c

示例2: js_read_file

/* reads a file from path and returns it as string */
int js_read_file(duk_context *ctx) {
	
	/* return error if no filename is given */
	if (duk_get_top(ctx) == 0) {
		printf("'read' expects one argument: 0 given\n");
		return DUK_RET_TYPE_ERROR;
	}
	
	/* also needs to be a string */
	if (!duk_is_string(ctx, 0)) {
		printf("'read' expects argument 1 of type string\n");
		return DUK_RET_TYPE_ERROR;
	}

	/* get the first argument */
	const char *filename = duk_get_string(ctx, 0);

	/* save file contents in this buffer */
	char *buffer = 0;
	/* how big is the file? */
	long length;

	/* try opening the file */
	FILE *fp = fopen(filename, "r");
	if (!fp) {
		printf("Failed to open file '%s'\n", filename);
		return DUK_RET_TYPE_ERROR;
	}
	
	/* get the files length... */
	fseek(fp, 0, SEEK_END);
	length = ftell(fp);
	fseek(fp, 0, SEEK_SET);
	/* ...allocate memory for its content... */
	buffer = malloc(length);
	/* ...and get its content if possible */
	if (buffer)
		fread(buffer, 1, length, fp);

	/* close the file again */
	fclose(fp);
	
	/* finally, push the string on the js stack */
	duk_push_string(ctx, buffer);
	free(buffer);
	return 1;
}
开发者ID:numpad,项目名称:generator,代码行数:48,代码来源:generate.c

示例3: test_1

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

	(void) udata;

	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, 1);
	duk_push_number(ctx, -123.456);
	duk_push_nan(ctx);
	duk_push_number(ctx, INFINITY);
	duk_push_string(ctx, "");
	duk_push_string(ctx, "foo");

	duk_push_string(ctx, "123");
	duk_push_string(ctx, "123.456");
	duk_push_string(ctx, "123.456e3");
	duk_push_string(ctx, "  -123.456e+3  ");
	duk_push_string(ctx, "NaN");
	duk_push_string(ctx, "-Infinity");
	duk_push_string(ctx, "+Infinity");
	duk_push_string(ctx, "Infinity");
	duk_push_string(ctx, "Infinityx");
	duk_push_string(ctx, "xInfinity");

	duk_push_string(ctx, "  Infinity  ");
	duk_push_object(ctx);
	duk_push_thread(ctx);
	duk_push_fixed_buffer(ctx, 0);    /* coerces like string: ToNumber('') = 0 */
	duk_push_fixed_buffer(ctx, 1024); /* coerces like string: ToNumber('\u0000\u0000...') = NaN */
	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++) {
		printf("index %ld, number: %lf\n", (long) i, (double) duk_to_number(ctx, i));
	}

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

示例4: check_2

/* same test but with one element checks, once per loop */
static duk_ret_t check_2(duk_context *ctx, void *udata) {
	int i;
	duk_ret_t rc;

	(void) udata;

	for (i = 0; i < 1000; i++) {
		rc = duk_check_stack_top(ctx, i + 1);
		if (rc == 0) {
			printf("duk_check_stack failed\n");
		}
		duk_push_int(ctx, 123);
	}

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

示例5: test_c_pcall_error2

static duk_ret_t test_c_pcall_error2(duk_context *ctx) {
	duk_idx_t i;
	duk_int_t rc;

	duk_require_stack(ctx, STACK_REQUIRE + 1);

	duk_push_c_function(ctx, my_func_error2, 0);
	rc = duk_pcall(ctx, 0 /*nargs*/);
	printf("duk_pcall: rc=%ld, value: %s\n", (long) rc, duk_safe_to_string(ctx, -1));

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

	printf("final top: %ld\n", (long) duk_get_top(ctx));
	return 0;
}
开发者ID:black13,项目名称:duktape_games,代码行数:17,代码来源:test-dev-valstack-checked-size-call.cpp

示例6: test_ecma_pcall_error

static duk_ret_t test_ecma_pcall_error(duk_context *ctx) {
	duk_idx_t i;
	duk_int_t rc;

	duk_require_stack(ctx, STACK_REQUIRE + 1);

	duk_eval_string(ctx, "(function () { print('hello from ecma func'); throw Error('ecma thrown'); })");
	rc = duk_pcall(ctx, 0 /*nargs*/);
	printf("duk_pcall: rc=%ld, value: %s\n", (long) rc, duk_safe_to_string(ctx, -1));

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

	printf("final top: %ld\n", (long) duk_get_top(ctx));
	return 0;
}
开发者ID:black13,项目名称:duktape_games,代码行数:17,代码来源:test-dev-valstack-checked-size-call.cpp

示例7: test_1

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

	duk_set_top(ctx, 0);

	remove_handlers(ctx);
	duk_eval_string(ctx, "Duktape.errThrow = function (err) { err.name = 'ForcedName'; return err; }");
	duk_pop(ctx);

	/* Throw with duk_throw(). */

	duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "range error: %d", 123);
	duk_throw(ctx);

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

示例8: js_OutlinedCircle

static duk_ret_t
js_OutlinedCircle(duk_context* ctx)
{
	bool    antialiased = false;
	color_t color;
	int     n_args;
	int     x, y, radius;

	n_args = duk_get_top(ctx);
	x = duk_to_int(ctx, 0);
	y = duk_to_int(ctx, 1);
	radius = duk_to_int(ctx, 2);
	color = duk_require_sphere_color(ctx, 3);
	if (n_args >= 5) antialiased = duk_require_boolean(ctx, 4);
	if (!is_skipped_frame()) al_draw_circle(x, y, radius, nativecolor(color), 1);
	return 0;
}
开发者ID:caivega,项目名称:minisphere,代码行数:17,代码来源:primitives.c

示例9: invoke

duk_ret_t JavaMethod::invoke(duk_context* ctx, JNIEnv* env, jobject javaThis) const {
  if (duk_get_top(ctx) != m_argumentLoaders.size()) {
    // Wrong number of arguments given - throw an error.
    duk_error(ctx, DUK_ERR_API_ERROR, "wrong number of arguments");
    // unreachable - duk_error never returns.
    return DUK_RET_API_ERROR;
  }

  std::vector<jvalue> args(m_argumentLoaders.size());
  // Load the arguments off the stack and convert to Java types.
  // Note we're going backwards since the last argument is at the top of the stack.
  for (ssize_t i = m_argumentLoaders.size() - 1; i >= 0; --i) {
    args[i] = m_argumentLoaders[i](ctx, env);
  }

  return m_methodBody(ctx, env, javaThis, args.data());
}
开发者ID:huzexin,项目名称:duktape-android,代码行数:17,代码来源:JavaMethod.cpp

示例10: test_1

/* Basic test. */
static duk_ret_t test_1(duk_context *ctx) {
	int i;

	duk_eval_string(ctx, "new RangeError('test error')");  /* 0 */
	duk_eval_string(ctx, "Error");  /* 1 */
	duk_eval_string(ctx, "RangeError");  /* 2 */
	duk_eval_string(ctx, "TypeError");  /* 3 */
	duk_eval_string(ctx, "Object");  /* 4 */
	duk_eval_string(ctx, "Function");  /* 5 */

	for (i = 1; i <= 5; i++) {
		printf("0 instanceof %d: %d\n", i, (int) duk_instanceof(ctx, 0, i));
	}

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

示例11: Line_Intersects_Selector

static duk_ret_t Line_Intersects_Selector(duk_context* ctx)
{
    int numArgs = duk_get_top(ctx);
    if (numArgs == 3 && GetValueObject<OBB>(ctx, 0, OBB_ID) && duk_is_number(ctx, 1) && duk_is_number(ctx, 2))
        return Line_Intersects_OBB_float_float(ctx);
    if (numArgs == 3 && GetValueObject<AABB>(ctx, 0, AABB_ID) && duk_is_number(ctx, 1) && duk_is_number(ctx, 2))
        return Line_Intersects_AABB_float_float(ctx);
    if (numArgs == 1 && GetValueObject<Capsule>(ctx, 0, Capsule_ID))
        return Line_Intersects_Capsule(ctx);
    if (numArgs == 1 && GetValueObject<Frustum>(ctx, 0, Frustum_ID))
        return Line_Intersects_Frustum(ctx);
    if (numArgs == 1 && GetValueObject<AABB>(ctx, 0, AABB_ID))
        return Line_Intersects_AABB(ctx);
    if (numArgs == 1 && GetValueObject<OBB>(ctx, 0, OBB_ID))
        return Line_Intersects_OBB(ctx);
    duk_error(ctx, DUK_ERR_ERROR, "Could not select function overload");
}
开发者ID:realXtend,项目名称:tundra-urho3d,代码行数:17,代码来源:LineBindings.cpp

示例12: test_1

static duk_ret_t test_1(duk_context *ctx) {
	duk_set_top(ctx, 0);

	duk_push_c_function(ctx, my_adder, 3 /*nargs*/);
	duk_push_int(ctx, 10);
	duk_push_int(ctx, 11);
	duk_push_int(ctx, 12);
	duk_push_int(ctx, 13);  /* clipped */
	duk_push_int(ctx, 14);  /* clipped */
	duk_call(ctx, 5);

	printf("result=%s\n", duk_to_string(ctx, -1));
	duk_pop(ctx);

	printf("final top: %ld\n", (long) duk_get_top(ctx));
	return 0;
}
开发者ID:black13,项目名称:duktape_games,代码行数:17,代码来源:test-call.cpp

示例13: test_2

int test_2(duk_context *ctx) {
	duk_set_top(ctx, 0);

	duk_push_c_function(ctx, my_adder, 3 /*nargs*/);
	duk_push_int(ctx, 10);
	duk_push_int(ctx, 11);
	duk_push_string(ctx, "foo");  /* causes error */
	duk_push_int(ctx, 13);  /* clipped */
	duk_push_int(ctx, 14);  /* clipped */
	duk_call(ctx, 5);

	printf("result=%s\n", duk_to_string(ctx, -1));
	duk_pop(ctx);

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

示例14: CallDisconnectSignal

void CallDisconnectSignal(duk_context* ctx, void* signal)
{
    int numArgs = duk_get_top(ctx);
    duk_push_number(ctx, (size_t)signal);
    duk_insert(ctx, 0);
    duk_push_global_object(ctx);
    duk_get_prop_string(ctx, -1, "_DisconnectSignal");
    duk_remove(ctx, -2); // Global object
    duk_insert(ctx, 0);
    duk_pcall(ctx, numArgs + 1);
    if (duk_get_boolean(ctx, -1)) // Last receiver disconnected
    {
        HashMap<void*, SharedPtr<SignalReceiver> >& signalReceivers = JavaScriptInstance::InstanceFromContext(ctx)->SignalReceivers();
        signalReceivers.Erase(signal);
    }
    duk_pop(ctx); // Result
}
开发者ID:realXtend,项目名称:tundra-urho3d,代码行数:17,代码来源:BindingsHelpers.cpp

示例15: test_getpropstring_a

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

	(void) udata;

	prep(ctx);

	rc = duk_get_prop_string(ctx, 0, "foo");
	printf("obj.foo -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1));
	duk_pop(ctx);

	rc = duk_get_prop_string(ctx, 0, "foo" "\x00" "bar");  /* embedded NUL terminates key */
	printf("obj.foo -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1));
	duk_pop(ctx);

	rc = duk_get_prop_string(ctx, 0, "nonexistent");
	printf("obj.nonexistent -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1));
	duk_pop(ctx);

	rc = duk_get_prop_string(ctx, 0, "123");
	printf("obj['123'] -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1));
	duk_pop(ctx);

	rc = duk_get_prop_string(ctx, 1, "nonexistent");
	printf("arr.nonexistent -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1));
	duk_pop(ctx);

	rc = duk_get_prop_string(ctx, 1, "2");
	printf("arr['2'] -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1));
	duk_pop(ctx);

	rc = duk_get_prop_string(ctx, 1, "length");
	printf("arr.length -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1));
	duk_pop(ctx);

	rc = duk_get_prop_string(ctx, 2, "5");
	printf("'test_string'['5'] -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1));
	duk_pop(ctx);

	rc = duk_get_prop_string(ctx, 2, "length");
	printf("'test_string'.length -> rc=%d, result='%s'\n", (int) rc, duk_to_string(ctx, -1));
	duk_pop(ctx);

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


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