本文整理汇总了C++中duk_to_string函数的典型用法代码示例。如果您正苦于以下问题:C++ duk_to_string函数的具体用法?C++ duk_to_string怎么用?C++ duk_to_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了duk_to_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test
void test(duk_context *ctx) {
int ret;
printf("top: %d\n", (int) duk_get_top(ctx));
ret = duk_get_global_string(ctx, "encodeURIComponent");
printf("top: %d\n", (int) duk_get_top(ctx));
printf("ret: %d\n", ret);
duk_push_string(ctx, "foo bar");
duk_call(ctx, 1);
printf("encoded: %s\n", duk_to_string(ctx, -1));
duk_pop(ctx);
printf("top: %d\n", (int) duk_get_top(ctx));
ret = duk_get_global_string(ctx, "doesNotExist");
printf("top: %d\n", (int) duk_get_top(ctx));
printf("ret: %d\n", ret);
printf("%s\n", duk_to_string(ctx, -1));
duk_pop(ctx);
printf("top: %d\n", (int) duk_get_top(ctx));
}
示例2: sys1_chmod
static int sys1_chmod(duk_context *ctx)
{
const char *path = duk_to_string(ctx, 0);
mode_t mode = duk_to_int(ctx, 1);
int rc;
rc = chmod(path, mode);
duk_push_int(ctx, rc);
return 1;
}
示例3: es_gumbo_find_by_id
static int
es_gumbo_find_by_id(duk_context *ctx)
{
es_gumbo_node_t *egn = es_get_native_obj(ctx, 0, &es_native_gumbo_node);
const char *id = duk_to_string(ctx, 1);
GumboNode *r = es_gumbo_find_by_id_r(egn->node, id);
if(r == NULL)
return 0;
push_gumbo_node(ctx, r, egn->output);
return 1;
}
示例4: 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;
}
示例5: js_Logger_write
static duk_ret_t
js_Logger_write(duk_context* ctx)
{
const char* text = duk_to_string(ctx, 0);
logger_t* logger;
duk_push_this(ctx);
logger = duk_require_sphere_obj(ctx, -1, "Logger");
write_log_line(logger, NULL, text);
return 0;
}
示例6: test_2c
/* duk_get_prop_string(), DUK_INVALID_INDEX */
int test_2c(duk_context *ctx) {
int rc;
prep(ctx);
rc = duk_get_prop_string(ctx, DUK_INVALID_INDEX, "foo");
printf("obj.foo -> rc=%d, result='%s'\n", rc, duk_to_string(ctx, -1));
duk_pop(ctx);
printf("final top: %d\n", duk_get_top(ctx));
return 0;
}
示例7: handle_set
static duk_ret_t handle_set(duk_context *ctx) {
/* 'this' binding: handler
* [0]: target
* [1]: key
* [2]: val
* [3]: receiver (proxy)
*/
const char *key = duk_to_string(ctx, 1);
const char *val = duk_to_string(ctx, 2);
printf("handle_set: key=%s, val=%s\n", key, val);
if (key != NULL && key[0] == '_') {
/* Indicate set failure for properties beginning with underscore. */
duk_push_false(ctx);
} else {
duk_push_true(ctx);
}
return 1;
}
示例8: es_gumbo_find_by_class
static int
es_gumbo_find_by_class(duk_context *ctx)
{
es_gumbo_node_t *egn = es_get_native_obj(ctx, 0, &es_native_gumbo_node);
const char *cls = duk_to_string(ctx, 1);
int idx = 0;
duk_push_array(ctx);
char **classlist = strvec_split(cls, ' ');
es_gumbo_find_by_class_r(egn->node, classlist, ctx, &idx, egn->output);
strvec_free(classlist);
return 1;
}
示例9: r2cmd
static int r2cmd(duk_context *ctx) {
char *ret;
int n = duk_get_top (ctx); /* #args */
if (n>0) {
const char *s = duk_to_string (ctx, 0);
ret = r_core_cmd_str (Gcore, s);
duk_push_string (ctx, ret);
free (ret);
return 1;
}
return 0;
}
示例10: test_3c
/* duk_get_prop_index(), DUK_INVALID_INDEX */
static duk_ret_t test_3c(duk_context *ctx) {
duk_ret_t rc;
prep(ctx);
rc = duk_get_prop_index(ctx, DUK_INVALID_INDEX, 123);
printf("obj[123] -> 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;
}
示例11: test_1
static duk_ret_t test_1(duk_context *ctx) {
duk_idx_t i, n;
prep(ctx);
duk_remove(ctx, -2); /* -> [ 123 345 ] */
n = duk_get_top(ctx);
for (i = 0; i < n; i++) {
printf("%ld: %s\n", (long) i, duk_to_string(ctx, i));
}
return 0;
}
示例12: duk__push_string
DUK_LOCAL void duk__push_string(duk_context *ctx, duk_bitdecoder_ctx *bd) {
duk_small_uint_t n;
duk_small_uint_t i;
duk_uint8_t *p;
n = (duk_small_uint_t) duk_bd_decode(bd, DUK__STRING_LENGTH_BITS);
p = (duk_uint8_t *) duk_push_fixed_buffer(ctx, n);
for (i = 0; i < n; i++) {
*p++ = (duk_uint8_t) duk_bd_decode(bd, DUK__STRING_CHAR_BITS);
}
duk_to_string(ctx, -1);
}
示例13: test_decode_invalid_char
static duk_ret_t test_decode_invalid_char(duk_context *ctx, void *udata) {
(void) udata;
duk_set_top(ctx, 0);
duk_push_string(ctx, "[email protected]=");
duk_push_int(ctx, 321); /* dummy */
duk_base64_decode(ctx, -2); /* buffer */
printf("base64 decode: %s\n", duk_to_string(ctx, -2));
printf("top after: %ld\n", (long) duk_get_top(ctx)); /* value + dummy */
duk_set_top(ctx, 0);
return 0;
}
示例14: sys1_stat
static int sys1_stat(duk_context *ctx)
{
const char *path = duk_to_string(ctx, 0);
struct stat buf;
int rc;
rc = stat(path, &buf);
sys1_push_stat(ctx, &buf);
duk_push_int(ctx, rc);
duk_put_prop_string(ctx, -2, "rc");
return 1;
}
示例15: sys1_getenv
static int sys1_getenv(duk_context *ctx)
{
const char *name = duk_to_string(ctx, 0);
char *val;
val = getenv(name);
if(val)
duk_push_string(ctx, val);
else
duk_push_undefined(ctx);
return 1;
}