本文整理汇总了C++中duk_push_string函数的典型用法代码示例。如果您正苦于以下问题:C++ duk_push_string函数的具体用法?C++ duk_push_string怎么用?C++ duk_push_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了duk_push_string函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:BpLife,项目名称:duktape,代码行数:14,代码来源:test-has-prop.c
示例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;
}
开发者ID:TechLord-Forever,项目名称:frida-gum,代码行数:39,代码来源:gumdukprocess.c
示例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();
}
开发者ID:BrandonTheHamm,项目名称:duktape,代码行数:38,代码来源:test-pushers.c
示例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;
}
开发者ID:Catethysis,项目名称:stm32js,代码行数:38,代码来源:main.c
示例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;
}
开发者ID:cherry-wb,项目名称:duktape,代码行数:39,代码来源:test-del-prop.c
示例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);
}
开发者ID:armornick,项目名称:duktape-misc,代码行数:14,代码来源:zip.c
示例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;
}
开发者ID:fatcerberus,项目名称:duktape,代码行数:14,代码来源:test-pcompile-invalid-stack.c
示例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;
}
开发者ID:CarterTsai,项目名称:duktape,代码行数:23,代码来源:test-get-string.c
示例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;
}
开发者ID:LaszloLango,项目名称:duktape,代码行数:50,代码来源:duk_cmdline.c
示例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);
}
开发者ID:armornick,项目名称:duktape-misc,代码行数:14,代码来源:main.c
示例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;
}
开发者ID:magul,项目名称:duktape,代码行数:15,代码来源:test-has-prop.c
示例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;
}
开发者ID:janneo,项目名称:duktape,代码行数:15,代码来源:test-get-prop.c
示例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;
}
开发者ID:caivega,项目名称:Mural,代码行数:14,代码来源:LocalStorage.cpp
示例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);
}
开发者ID:petervaro,项目名称:hackathon,代码行数:15,代码来源:built_ins.c
示例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;
}
开发者ID:NabilNoaman,项目名称:tangram-es,代码行数:57,代码来源:styleContext.cpp
示例16: duk_bi_date_format_parts_strftime
DUK_INTERNAL duk_bool_t duk_bi_date_format_parts_strftime(duk_context *ctx, duk_int_t *parts, duk_int_t tzoffset, duk_small_uint_t flags) {
char buf[DUK__STRFTIME_BUF_SIZE];
struct tm tm;
const char *fmt;
DUK_UNREF(tzoffset);
/* If the platform doesn't support the entire Ecmascript range, we need
* to return 0 so that the caller can fall back to the default formatter.
*
* For now, assume that if time_t is 8 bytes or more, the whole Ecmascript
* range is supported. For smaller time_t values (4 bytes in practice),
* assumes that the signed 32-bit range is supported.
*
* XXX: detect this more correctly per platform. The size of time_t is
* probably not an accurate guarantee of strftime() supporting or not
* supporting a large time range (the full Ecmascript range).
*/
if (sizeof(time_t) < 8 &&
(parts[DUK_DATE_IDX_YEAR] < 1970 || parts[DUK_DATE_IDX_YEAR] > 2037)) {
/* be paranoid for 32-bit time values (even avoiding negative ones) */
return 0;
}
DUK_MEMZERO(&tm, sizeof(tm));
tm.tm_sec = parts[DUK_DATE_IDX_SECOND];
tm.tm_min = parts[DUK_DATE_IDX_MINUTE];
tm.tm_hour = parts[DUK_DATE_IDX_HOUR];
tm.tm_mday = parts[DUK_DATE_IDX_DAY]; /* already one-based */
tm.tm_mon = parts[DUK_DATE_IDX_MONTH] - 1; /* one-based -> zero-based */
tm.tm_year = parts[DUK_DATE_IDX_YEAR] - 1900;
tm.tm_wday = parts[DUK_DATE_IDX_WEEKDAY];
tm.tm_isdst = 0;
DUK_MEMZERO(buf, sizeof(buf));
if ((flags & DUK_DATE_FLAG_TOSTRING_DATE) && (flags & DUK_DATE_FLAG_TOSTRING_TIME)) {
fmt = "%c";
} else if (flags & DUK_DATE_FLAG_TOSTRING_DATE) {
fmt = "%x";
} else {
DUK_ASSERT(flags & DUK_DATE_FLAG_TOSTRING_TIME);
fmt = "%X";
}
(void) strftime(buf, sizeof(buf) - 1, fmt, &tm);
DUK_ASSERT(buf[sizeof(buf) - 1] == 0);
duk_push_string(ctx, buf);
return 1;
}
开发者ID:janneo,项目名称:duktape,代码行数:49,代码来源:duk_bi_date_unix.c
示例17: Atomic_SplitPath
static int Atomic_SplitPath(duk_context* ctx)
{
String path = duk_require_string(ctx, 0);
String pathName;
String fileName;
String ext;
duk_push_object(ctx);
SplitPath(path, pathName, fileName, ext);
duk_push_string(ctx, pathName.CString());
duk_put_prop_string(ctx, -2, "pathName");
duk_push_string(ctx, fileName.CString());
duk_put_prop_string(ctx, -2, "fileName");
duk_push_string(ctx, ext.CString());
duk_put_prop_string(ctx, -2, "ext");
return 1;
}
开发者ID:adebgamesoft,项目名称:AtomicGameEngine,代码行数:24,代码来源:JSFileSystem.cpp
示例18: test_3b
/* source: non-buffer, target: dynamic buffer */
static duk_ret_t test_3b(duk_context *ctx) {
void *q;
duk_size_t sz;
duk_set_top(ctx, 0);
duk_push_string(ctx, "foo");
q = duk_to_dynamic_buffer(ctx, -1, &sz);
printf("q is NULL: %d\n", (q == NULL ? 1 : 0));
printf("sz=%lu\n", (unsigned long) sz);
dump_buffer(ctx);
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
开发者ID:OakLabsInc,项目名称:duktape,代码行数:16,代码来源:test-to-fixed-dynamic-buffer.c
示例19: DefineProperty
void DefineProperty(duk_context* ctx, const char* propertyName, duk_c_function getFunc, duk_c_function setFunc)
{
duk_push_string(ctx, propertyName);
if (setFunc)
{
duk_push_c_function(ctx, getFunc, 0);
duk_push_c_function(ctx, setFunc, 1);
duk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER | DUK_DEFPROP_HAVE_SETTER);
}
else
{
duk_push_c_function(ctx, getFunc, 0);
duk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_GETTER);
}
}
开发者ID:realXtend,项目名称:tundra-urho3d,代码行数:15,代码来源:BindingsHelpers.cpp
示例20: test_basic
static duk_ret_t test_basic(duk_context *ctx, void *udata) {
duk_bool_t ret;
(void) udata;
printf("top: %ld\n", (long) duk_get_top(ctx));
duk_push_string(ctx, "1.2.3");
ret = duk_put_global_string(ctx, "myAppVersion" "\x00" "ignored");
printf("top: %ld\n", (long) duk_get_top(ctx));
printf("ret: %ld\n", (long) ret);
duk_eval_string_noresult(ctx, "print(myAppVersion);");
printf("top: %ld\n", (long) duk_get_top(ctx));
duk_push_string(ctx, "nulval");
ret = duk_put_global_lstring(ctx, "nul" "\x00" "keyx", 7);
printf("top: %ld\n", (long) duk_get_top(ctx));
printf("ret: %ld\n", (long) ret);
duk_eval_string_noresult(ctx, "print(new Function('return this')()['nul\\u0000key']);");
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
开发者ID:fatcerberus,项目名称:duktape,代码行数:24,代码来源:test-put-global-string.c
注:本文中的duk_push_string函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论