本文整理汇总了C++中duk_push_int函数的典型用法代码示例。如果您正苦于以下问题:C++ duk_push_int函数的具体用法?C++ duk_push_int怎么用?C++ duk_push_int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了duk_push_int函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: 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);
duk_get_prop_string(ctx, -1, "\xFF" "ptr"); font = duk_get_pointer(ctx, -1); duk_pop(ctx);
duk_pop(ctx);
duk_push_int(ctx, get_text_width(font, text));
return 1;
}
开发者ID:carriercomm,项目名称:minisphere,代码行数:13,代码来源:font.c
示例17: API__getmininginfo
static duk_ret_t API__getmininginfo ( duk_context * ctx )
{
duk_idx_t idx;
idx = duk_push_object(ctx);
duk_push_int ( ctx, nBestHeight );
duk_put_prop_string ( ctx, idx, "blocks" );
duk_push_int ( ctx, nLastBlockSize );
duk_put_prop_string ( ctx, idx, "currentblocksize" );
duk_push_int ( ctx, nLastBlockTx );
duk_put_prop_string ( ctx, idx, "currentblocktx" );
duk_push_number ( ctx, GetDifficulty(NULL) );
duk_put_prop_string ( ctx, idx, "difficulty" );
duk_push_string ( ctx, GetWarnings("statusbar").c_str() );
duk_put_prop_string ( ctx, idx, "errors" );
duk_push_boolean ( ctx, GetBoolArg ("-gen") );
duk_put_prop_string ( ctx, idx, "generate" );
duk_push_int ( ctx, GetArg ( "-genproclimit", -1 ) );
duk_put_prop_string ( ctx, idx, "genproclimit" );
duk_push_int ( ctx, 0 ); /* (TODO) */
duk_put_prop_string ( ctx, idx, "hashespersec" );
duk_push_number ( ctx, mempool.size() );
duk_put_prop_string ( ctx, idx, "pooledtx" );
duk_push_boolean ( ctx, fTestNet );
duk_put_prop_string ( ctx, idx, "testnet" );
return 1;
}
开发者ID:protokashey,项目名称:emerobot,代码行数:38,代码来源:emerobot_api_bitcoin.cpp
示例18: test
void test(duk_context *ctx) {
duk_idx_t i, funcidx, argcount;
duk_ret_t rc;
/* test C function arg count variants */
duk_push_c_function(ctx, my_int_adder, 0); /* [0] = c func with 0 args */
duk_push_c_function(ctx, my_int_adder, 1); /* [1] = c func with 1 arg */
duk_push_c_function(ctx, my_int_adder, 2); /* [2] = c func with 2 args */
duk_push_c_function(ctx, my_int_adder, DUK_VARARGS); /* [3] = c func with varargs */
for (funcidx = 0; funcidx < 4; funcidx++) {
for (argcount = 0; argcount < 5; argcount++) {
duk_dup(ctx, funcidx);
for (i = 0; i < argcount; i++) {
duk_push_int(ctx, i + 1); /* 1, 2, 3, ... */
}
/* [ ... func <args> ] */
duk_call(ctx, argcount);
printf("funcidx=%ld, argcount=%ld -> result=%ld\n",
(long) funcidx, (long) argcount, (long) duk_to_int(ctx, -1));
duk_pop(ctx);
}
}
/* test C function return value 0 and negative */
duk_set_top(ctx, 0);
duk_push_c_function(ctx, my_zero_ret, 0);
duk_call(ctx, 0);
printf("top after calling my_zero_ret: %ld, retval='%s'\n",
(long) duk_get_top(ctx), duk_to_string(ctx, -1));
duk_pop(ctx);
duk_set_top(ctx, 0);
duk_push_c_function(ctx, my_neg_ret, 0);
rc = duk_pcall(ctx, 0);
printf("top after calling my_neg_ret: %ld, rc=%d, retval='%s'\n",
(long) duk_get_top(ctx), (int) rc, duk_to_string(ctx, -1));
duk_pop(ctx);
duk_set_top(ctx, 0);
duk_push_c_function(ctx, my_type_error_ret, 0);
rc = duk_pcall(ctx, 0);
printf("top after calling my_type_error_ret: %ld, rc=%d, retval='%s'\n",
(long) duk_get_top(ctx), (int) rc, duk_to_string(ctx, -1));
duk_pop(ctx);
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:50,代码来源:test-push-cfunc.c
示例19: duk_builtin_duk_object_gc
int duk_builtin_duk_object_gc(duk_context *ctx) {
#ifdef DUK_USE_MARK_AND_SWEEP
duk_hthread *thr = (duk_hthread *) ctx;
int flags;
int rc;
flags = duk_get_int(ctx, 0);
rc = duk_heap_mark_and_sweep(thr->heap, flags);
duk_push_int(ctx, rc);
return 1;
#else
return 0;
#endif
}
开发者ID:JoshEngebretson,项目名称:duktape,代码行数:14,代码来源:duk_builtin_duk.c
示例20: check_1
/* demonstrate how using one large duk_check_stack_top() before such
* a loop works.
*/
int check_1(duk_context *ctx) {
int i;
int rc;
rc = duk_check_stack_top(ctx, 1000);
printf("rc=%d\n", rc);
for (i = 0; i < 1000; i++) {
duk_push_int(ctx, 123);
}
printf("final top: %d\n", duk_get_top(ctx));
return 0;
}
开发者ID:BpLife,项目名称:duktape,代码行数:17,代码来源:test-check-require-stack-top.c
注:本文中的duk_push_int函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论