本文整理汇总了C++中duk_push_string函数的典型用法代码示例。如果您正苦于以下问题:C++ duk_push_string函数的具体用法?C++ duk_push_string怎么用?C++ duk_push_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了duk_push_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_1e
/* duk_has_prop(), not an object */
int test_1e(duk_context *ctx) {
int rc;
duk_set_top(ctx, 0);
duk_push_null(ctx);
duk_push_string(ctx, "foo");
rc = duk_has_prop(ctx, -2);
printf("null.foo -> rc=%d\n", rc);
printf("final top: %d\n", duk_get_top(ctx));
return 0;
}
示例2: gum_emit_module
static gboolean
gum_emit_module (const GumModuleDetails * details,
gpointer user_data)
{
GumDukMatchContext * mc = user_data;
GumDukScope * scope = mc->scope;
duk_context * ctx = scope->ctx;
gboolean proceed = TRUE;
duk_push_heapptr (ctx, mc->on_match);
duk_push_object (ctx);
duk_push_string (ctx, details->name);
duk_put_prop_string (ctx, -2, "name");
_gum_duk_push_native_pointer (ctx,
GSIZE_TO_POINTER (details->range->base_address), scope->core);
duk_put_prop_string (ctx, -2, "base");
duk_push_uint (ctx, details->range->size);
duk_put_prop_string (ctx, -2, "size");
duk_push_string (ctx, details->path);
duk_put_prop_string (ctx, -2, "path");
if (_gum_duk_scope_call_sync (scope, 1))
{
if (duk_is_string (ctx, -1))
proceed = strcmp (duk_require_string (ctx, -1), "stop") != 0;
}
else
{
proceed = FALSE;
}
duk_pop (ctx);
return proceed;
}
示例3: test
void test(duk_context *ctx) {
const char *res;
duk_push_undefined(ctx); PRINTTOP();
duk_push_null(ctx); PRINTTOP();
duk_push_true(ctx); PRINTTOP();
duk_push_false(ctx); PRINTTOP();
duk_push_boolean(ctx, -1); PRINTTOP();
duk_push_boolean(ctx, 0); PRINTTOP();
duk_push_boolean(ctx, 1); PRINTTOP();
duk_push_number(ctx, 123.4); PRINTTOP();
duk_push_int(ctx, 234); PRINTTOP();
duk_push_nan(ctx); PRINTTOP();
res = duk_push_string(ctx, "foo"); PRINTRESTOP();
res = duk_push_string(ctx, "foo\0bar\0"); PRINTRESTOP();
res = duk_push_string(ctx, ""); PRINTRESTOP(); /* pushes empty */
res = duk_push_string(ctx, NULL); PRINTRESTOP(); /* pushes a NULL */
res = duk_push_lstring(ctx, "foobar", 4); PRINTRESTOP();
res = duk_push_lstring(ctx, "foob\0\0", 6); PRINTRESTOP();
res = duk_push_lstring(ctx, "\0", 1); PRINTRESTOP(); /* pushes 1-byte string (0x00) */
res = duk_push_lstring(ctx, "\0", 0); PRINTRESTOP(); /* pushes empty */
res = duk_push_lstring(ctx, NULL, 0); PRINTRESTOP(); /* pushes empty */
res = duk_push_lstring(ctx, NULL, 10); PRINTRESTOP(); /* pushes empty */
res = duk_push_sprintf(ctx, "foo"); PRINTRESTOP();
res = duk_push_sprintf(ctx, "foo %d %s 0x%08lx", 123, "bar", (long) 0x1234cafe); PRINTRESTOP();
res = duk_push_sprintf(ctx, ""); PRINTRESTOP();
res = duk_push_sprintf(ctx, NULL); PRINTRESTOP();
res = test_vsprintf_3x_int(ctx, 2, 3, 5); PRINTRESTOP();
res = test_vsprintf_empty(ctx, 2, 3, 5); PRINTRESTOP();
res = test_vsprintf_null(ctx, 2, 3, 5); PRINTRESTOP();
duk_push_pointer(ctx, (void *) 0); PRINTTOP();
duk_push_pointer(ctx, (void *) 0xdeadbeef); PRINTTOP();
}
示例4: main
int main(int argc, char *argv[]) {
/**(uint32_t *)0x40023830 |= 0x8;
*(uint32_t *)0x40020C00 |= 0x55000000;
*(uint32_t *)0x40020C14 = 0x00000000;
while(1) {
*(uint32_t *)0x40020C14 = 0x00000000;
delay();
*(uint32_t *)0x40020C14 = 0x00008000;
delay();
}
duk_context *ctx = duk_create_heap_default();
duk_eval_string(ctx, "'Hello world!'");
duk_destroy_heap(ctx);
*/
*(uint32_t *)0x40023830 |= 0x8;
*(uint32_t *)0x40020C00 |= 0x55000000;
*(uint32_t *)0x40020C14 = 0x00000000;
ctx = duk_create_heap_default();
duk_push_global_object(ctx);
duk_push_c_function(ctx, LED_Toggle, DUK_VARARGS);
duk_put_prop_string(ctx, -2, "LED_Toggle");
duk_push_string(ctx, "blink = function() { LED_Toggle(); };");
duk_safe_call(ctx, safeEval, 1, 1);
while (1)
{
duk_push_global_object(ctx);
duk_get_prop_string(ctx, -1, "blink");
duk_push_string(ctx, "0");
duk_safe_call(ctx, safeCall, 1, 0);
duk_pop_2(ctx);
//for(volatile int i = 0; i < 100000; i++);
//delay();
}
return 0;
}
示例5: test_1a
/* duk_del_prop(), success cases */
static duk_ret_t test_1a(duk_context *ctx) {
duk_ret_t rc;
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;
}
示例6: dukzip_push_unzfile
static void dukzip_push_unzfile(duk_context *ctx, unzFile archive, const char *filename) {
/* create object with readable Dukzip archive prototype */
duk_push_object(ctx);
duk_get_global_string(ctx, DUKZIP_UNZ_PROTOTYPE);
duk_set_prototype(ctx, -2);
/* set the archive pointer data */
duk_push_pointer(ctx, archive);
duk_put_prop_string(ctx, -2, ZIPHANDLE_PROP);
/* set path property */
duk_push_string(ctx, filename);
duk_put_prop_string(ctx, -2, ZIPFILENAME_PROP);
}
示例7: test_top_1
duk_ret_t test_top_1(duk_context *ctx, void *udata) {
duk_int_t rc;
(void) udata;
duk_push_string(ctx, "dummy");
printf("top before: %ld\n", (long) duk_get_top(ctx));
rc = duk_pcompile(ctx, 0);
printf("duk_pcompile() rc: %ld\n", (long) rc);
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
示例8: test_get_string
static duk_ret_t test_get_string(duk_context *ctx) {
duk_idx_t i, n;
duk_push_undefined(ctx);
duk_push_null(ctx);
duk_push_true(ctx);
duk_push_false(ctx);
duk_push_string(ctx, "");
duk_push_string(ctx, "foo");
duk_push_lstring(ctx, "foo\0bar", 7);
duk_push_string(ctx, "\xe1\x88\xb4xyz"); /* 4 chars, first char utf-8 encoded U+1234 */
duk_push_nan(ctx);
duk_push_object(ctx);
n = duk_get_top(ctx);
printf("top: %ld\n", (long) n);
for (i = 0; i < n; i++) {
printf("index %ld: ", (long) i);
dump((const unsigned char *) duk_get_string(ctx, i));
}
return 0;
}
示例9: handle_fh
static int handle_fh(duk_context *ctx, FILE *f, const char *filename) {
char *buf = NULL;
int len;
int got;
int rc;
int retval = -1;
if (fseek(f, 0, SEEK_END) < 0) {
goto error;
}
len = (int) ftell(f);
if (fseek(f, 0, SEEK_SET) < 0) {
goto error;
}
buf = (char *) malloc(len);
if (!buf) {
goto error;
}
got = fread((void *) buf, (size_t) 1, (size_t) len, f);
duk_push_lstring(ctx, buf, got);
duk_push_string(ctx, filename);
free(buf);
buf = NULL;
interactive_mode = 0; /* global */
rc = duk_safe_call(ctx, wrapped_compile_execute, 2 /*nargs*/, 1 /*nret*/);
if (rc != DUK_EXEC_SUCCESS) {
print_pop_error(ctx, stderr);
goto error;
} else {
duk_pop(ctx);
retval = 0;
}
/* fall thru */
cleanup:
if (buf) {
free(buf);
}
return retval;
error:
fprintf(stderr, "error in executing file %s\n", filename);
fflush(stderr);
goto cleanup;
}
示例10: duknode_push_argv
static void duknode_push_argv(duk_context *ctx, int argc, const char *argv[]) {
duk_get_global_string(ctx, "process");
duk_idx_t arg_array_index; int i;
arg_array_index = duk_push_array(ctx);
for (i = 0; i < argc; i++) {
duk_push_string(ctx, argv[i]);
duk_put_prop_index(ctx, arg_array_index, i);
}
duk_put_prop_string(ctx, -2, "argv");
duk_pop(ctx);
}
示例11: test_1b
/* duk_has_prop(), invalid index */
static duk_ret_t test_1b(duk_context *ctx, void *udata) {
duk_ret_t rc;
(void) udata;
prep(ctx);
duk_push_string(ctx, "foo");
rc = duk_has_prop(ctx, 234);
printf("obj.foo -> rc=%d\n", (int) rc);
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
示例12: test_1e
/* duk_get_prop(), not object coercible */
static duk_ret_t test_1e(duk_context *ctx) {
duk_ret_t rc;
duk_set_top(ctx, 0);
duk_push_null(ctx);
duk_push_string(ctx, "foo");
rc = duk_get_prop(ctx, -2);
printf("null.foo -> 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;
}
示例13: w_LocalStorage_prototype_getItem
int w_LocalStorage_prototype_getItem(duk_context *ctx)
{
const char *key = duk_require_string(ctx, 0);
duk_push_this(ctx); /* this */
duk_get_prop_string(ctx, -1, "__MURAL_DATA__"); /* this, __MURAL_DATA__ */
duk_get_prop_string(ctx, -1, key); /* this, __MURAL_DATA__, value */
const char *value = duk_to_string(ctx, -1); /* this, __MURAL_DATA__, string(value) */
duk_pop_3(ctx);
duk_push_string(ctx, value);
return 1;
}
示例14: kbjs_register_built_ins
/*----------------------------------------------------------------------------*/
void
kbjs_register_built_ins(duk_context *context)
{
/* STACK: [..., global] */
duk_push_global_object(context);
/* STACK: [..., global, "sleep"] */
duk_push_string(context, SLEEP_FUNC_NAME);
/* STACK: [..., global, "sleep", function] */
duk_push_c_function(context, kbjs_sleep, (duk_idx_t)1);
/* STACK: [..., global] */
duk_put_prop(context, (duk_idx_t)-3);
/* STACK: [...] */
duk_pop(context);
}
示例15: switch
void StyleContext::parseSceneGlobals(const YAML::Node& node, const std::string& key, int seqIndex,
duk_idx_t dukObject) {
switch(node.Type()) {
case YAML::NodeType::Scalar:
if (key.size() == 0) {
duk_push_string(m_ctx, node.Scalar().c_str());
duk_put_prop_index(m_ctx, dukObject, seqIndex);
} else {
auto nodeValue = node.Scalar();
if (nodeValue.compare(0, 8, "function") == 0) {
duk_push_string(m_ctx, key.c_str()); // push property key
duk_push_string(m_ctx, nodeValue.c_str()); // push function string
duk_push_string(m_ctx, "");
if (duk_pcompile(m_ctx, DUK_COMPILE_FUNCTION) == 0) { // compile function
duk_put_prop(m_ctx, -3); // put {key: function()}
} else {
LOGW("Compile failed in global function: %s\n%s\n---",
duk_safe_to_string(m_ctx, -1),
nodeValue.c_str());
duk_pop(m_ctx); //pop error
duk_pop(m_ctx); //pop key
// push property as a string
duk_push_string(m_ctx, nodeValue.c_str());
duk_put_prop_string(m_ctx, dukObject, key.c_str());
}
} else {
duk_push_string(m_ctx, nodeValue.c_str());
duk_put_prop_string(m_ctx, dukObject, key.c_str());
}
}
break;
case YAML::NodeType::Sequence:
{
auto seqObj = duk_push_array(m_ctx);
for (int i = 0; i < node.size(); i++) {
parseSceneGlobals(node[i], "", i, seqObj);
}
duk_put_prop_string(m_ctx, seqObj-1, key.c_str());
break;
}
case YAML::NodeType::Map:
{
//duk_push_string(m_ctx, key.c_str());
auto mapObj = duk_push_object(m_ctx);
for (auto& mapNode : node) {
auto itemKey = mapNode.first.Scalar();
parseSceneGlobals(mapNode.second, itemKey, 0, mapObj);
}
duk_put_prop_string(m_ctx, mapObj-1, key.c_str());
}
default:
break;
}
return;
}