本文整理汇总了C++中duk_push_null函数的典型用法代码示例。如果您正苦于以下问题:C++ duk_push_null函数的具体用法?C++ duk_push_null怎么用?C++ duk_push_null使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了duk_push_null函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_2a
static duk_ret_t test_2a(duk_context *ctx, void *udata) {
(void) udata;
/* Test first with nothing on stack index -3. */
duk_safe_call(ctx, test__null, NULL, 0, 1); printf("%s\n", duk_safe_to_string(ctx, 0));
duk_pop(ctx);
duk_set_top(ctx, 0); duk_push_undefined(ctx); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_null(ctx); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_true(ctx); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_false(ctx); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_number(ctx, 123.0); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_string(ctx, "foo\x00" "bar"); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_fixed_buffer(ctx, 16); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_pointer(ctx, NULL); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_pointer(ctx, (void *) 0xdeadbeefUL); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_object(ctx); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_array(ctx); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_c_function(ctx, dummy_func, 0); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_c_lightfunc(ctx, dummy_func, 0, 0, 0); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_eval_string(ctx, "(function dummy(){})"); test__require_calls(ctx);
duk_set_top(ctx, 0); duk_push_thread(ctx); test__require_calls(ctx);
printf("done\n");
return 0;
}
示例2: test_1
static duk_ret_t test_1(duk_context *ctx) {
duk_size_t i, n;
char *buf;
duk_set_top(ctx, 0);
duk_push_undefined(ctx);
duk_push_null(ctx);
duk_push_true(ctx);
duk_push_false(ctx);
duk_push_nan(ctx);
duk_push_number(ctx, -INFINITY);
duk_push_number(ctx, +INFINITY);
duk_push_number(ctx, -0.0);
duk_push_number(ctx, +0.0);
duk_push_int(ctx, 123);
duk_push_string(ctx, "foo");
duk_push_lstring(ctx, "foo\0bar", 7); /* internal NULs are kept */
duk_push_object(ctx);
buf = (char *) duk_push_fixed_buffer(ctx, 0);
buf = (char *) duk_push_fixed_buffer(ctx, 16);
for (i = 0; i < 16; i++) {
buf[i] = i;
}
buf = (char *) duk_push_dynamic_buffer(ctx, 0);
buf = (char *) duk_push_dynamic_buffer(ctx, 16);
for (i = 0; i < 16; i++) {
buf[i] = i;
}
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;
void *ptr;
duk_size_t sz;
duk_dup(ctx, i);
t1 = duk_get_type(ctx, -1);
sz = (duk_size_t) 0xdeadbeef;
ptr = duk_to_buffer(ctx, -1, &sz);
t2 = duk_get_type(ctx, -1);
printf("index %ld, type %ld -> %ld, ptr-is-NULL %d, size %lu\n",
(long) i, (long) t1, (long) t2,
(sz == 0 ? -1 : (ptr == NULL ? 1 : 0)),
(unsigned long) sz);
dump_buffer(ctx);
duk_pop(ctx);
/* just check that this doesn't break */
duk_dup(ctx, i);
ptr = duk_to_buffer(ctx, -1, NULL);
duk_pop(ctx);
}
return 0;
}
示例3: test_string
static duk_ret_t test_string(duk_context *ctx, void *udata) {
duk_idx_t i, n;
(void) udata;
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_default(ctx, i, "default"));
}
return 0;
}
示例4: duk_bi_object_getprototype_shared
/* Shared helper to implement Object.getPrototypeOf and the ES6
* Object.prototype.__proto__ getter.
*
* https://people.mozilla.org/~jorendorff/es6-draft.html#sec-get-object.prototype.__proto__
*/
duk_ret_t duk_bi_object_getprototype_shared(duk_context *ctx) {
duk_hobject *h;
/* magic: 0=getter call, 1=Object.getPrototypeOf */
if (duk_get_current_magic(ctx) == 0) {
duk_push_this_coercible_to_object(ctx);
duk_insert(ctx, 0);
}
h = duk_require_hobject(ctx, 0);
DUK_ASSERT(h != NULL);
/* XXX: should the API call handle this directly, i.e. attempt
* to duk_push_hobject(ctx, null) would push a null instead?
* (On the other hand 'undefined' would be just as logical, but
* not wanted here.)
*/
if (h->prototype) {
duk_push_hobject(ctx, h->prototype);
} else {
duk_push_null(ctx);
}
return 1;
}
示例5: test
void test(duk_context *ctx) {
int i, n;
duk_push_c_function(ctx, func, 0);
duk_push_undefined(ctx);
duk_push_null(ctx);
duk_push_true(ctx);
duk_push_false(ctx);
duk_push_number(ctx, 123.456);
duk_push_string(ctx, "foo");
duk_push_object(ctx);
duk_push_array(ctx);
duk_push_fixed_buffer(ctx, 16);
duk_push_pointer(ctx, (void *) 0xdeadbeef);
n = duk_get_top(ctx);
printf("top: %d\n", n);
for (i = 1; i < n; i++) {
duk_dup(ctx, 0);
duk_dup(ctx, i);
duk_call_method(ctx, 0); /* [ ... func this ] -> [ ret ] */
duk_pop(ctx);
}
}
示例6: test_basic
static duk_ret_t test_basic(duk_context *ctx, void *udata) {
duk_idx_t i, n;
duk_int_t rc;
(void) udata;
duk_push_undefined(ctx);
duk_push_null(ctx);
duk_push_true(ctx);
duk_push_false(ctx);
duk_push_string(ctx, "foo");
duk_push_int(ctx, 123);
duk_push_object(ctx);
duk_push_pointer(ctx, (void *) NULL);
duk_push_pointer(ctx, (void *) 0xdeadbeefUL);
n = duk_get_top(ctx);
printf("top: %ld\n", (long) n);
for (i = 0; i <= n; i++) {
rc = duk_safe_call(ctx, safe_helper, (void *) i, 0, 1);
if (rc != DUK_EXEC_SUCCESS) {
printf("index %ld: %s\n", (long) i, duk_safe_to_string(ctx, -1));
}
duk_pop(ctx);
}
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
示例7: test
void test(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, "foo");
duk_push_string(ctx, "123");
duk_push_number(ctx, -INFINITY);
duk_push_number(ctx, -123456789.0);
duk_push_number(ctx, -0.0);
duk_push_number(ctx, +0.0);
duk_push_number(ctx, +123456789.0);
duk_push_number(ctx, +INFINITY);
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++) {
double d = duk_get_number(ctx, i);
int c = fpclassify(d);
printf("index %ld: number %lf, FP_NAN=%d, FP_INFINITE=%d, FP_ZERO=%d, FP_SUBNORMAL=%d, FP_NORMAL=%d, signbit=%d\n",
(long) i, d, (c == FP_NAN ? 1 : 0), (c == FP_INFINITE ? 1 : 0), (c == FP_ZERO ? 1 : 0),
(c == FP_SUBNORMAL ? 1 : 0), (c == FP_NORMAL ? 1 : 0), (signbit(d) ? 1 : 0));
}
}
示例8: test_lstring
static duk_ret_t test_lstring(duk_context *ctx, void *udata) {
duk_idx_t i, n;
(void) udata;
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++) {
const char *buf;
size_t len;
len = (size_t) 0xdeadbeefUL;
buf = duk_get_lstring_default(ctx, i, &len, "default!", 7);
printf("index %ld: length %lu: ",
(long) i, (unsigned long) len);
dump((const unsigned char *) buf);
buf = duk_get_lstring_default(ctx, i, NULL, "default!", 7);
printf("index %ld: ", (long) i);
dump((const unsigned char *) buf);
}
return 0;
}
示例9: test
void test(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_int(ctx, 123);
duk_push_object(ctx);
duk_push_fixed_buffer(ctx, 0);
duk_push_fixed_buffer(ctx, 1024);
duk_push_dynamic_buffer(ctx, 0);
duk_push_dynamic_buffer(ctx, 2048);
n = duk_get_top(ctx);
printf("top: %ld\n", (long) n);
for (i = 0; i < n; i++) {
void *buf;
duk_size_t len;
len = (duk_size_t) 0xdeadbeef;
buf = duk_get_buffer(ctx, i, &len);
if (len == 0) {
/* avoid printing 'buf' if len is zero, as it is not predictable */
printf("index %ld: length 0\n", (long) i);
} else {
printf("index %ld: length %lu, ptr-is-NULL %d\n",
(long) i, (unsigned long) len, (buf == NULL ? 1 : 0));
}
}
}
示例10: test_1
int test_1(duk_context *ctx) {
int 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_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: %d\n", n);
for (i = 0; i < n; i++) {
duk_to_undefined(ctx, i);
printf("index %d, is-undefined: %d\n", i, duk_is_undefined(ctx, i));
}
return 0;
}
示例11: nsp_texture_constructor
static duk_ret_t nsp_texture_constructor(duk_context *ctx) {
int width = duk_require_int(ctx, 0);
int height = duk_require_int(ctx, 1);
if (width < 1 || height < 1) {
duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "Width and height must be positive");
duk_throw(ctx);
}
bool has_transparency;
uint16_t transparent_color;
if ((has_transparency = duk_is_number(ctx, 2))) {
transparent_color = (uint16_t)duk_get_int(ctx, 2);
}
duk_push_this(ctx);
duk_push_fixed_buffer(ctx, width * height * 2);
duk_put_prop_string(ctx, -2, "bitmap");
duk_push_int(ctx, width);
duk_put_prop_string(ctx, -2, "width");
duk_push_int(ctx, height);
duk_put_prop_string(ctx, -2, "height");
if (has_transparency) {
duk_push_int(ctx, transparent_color);
} else {
duk_push_null(ctx);
}
duk_put_prop_string(ctx, -2, "transparentColor");
return 0;
}
示例12: como_push_worker_value
void como_push_worker_value (duk_context *ctx, comoQueue *queue){
switch(queue->type){
case DUK_TYPE_UNDEFINED :
duk_push_undefined(ctx);
break;
case DUK_TYPE_NULL :
duk_push_null(ctx);
break;
case DUK_TYPE_OBJECT :
duk_push_string(ctx, queue->data);
duk_json_decode(ctx, -1);
break;
case DUK_TYPE_POINTER :
duk_push_pointer(ctx, queue->data);
break;
case DUK_TYPE_STRING :
duk_push_string(ctx, queue->data);
break;
default :
assert(0 && "Duk Type Error");
}
}
示例13: test_nargs_minus1
static duk_ret_t test_nargs_minus1(duk_context *ctx, void *udata) {
duk_int_t rc;
(void) udata;
duk_push_null(ctx);
duk_push_null(ctx);
duk_push_null(ctx);
printf("top before: %ld\n", (long) duk_get_top(ctx));
rc = duk_safe_call(ctx, dummy, NULL, -1 /*nargs, negative*/, 0 /*nrets*/);
printf("duk_safe_call rc: %ld\n", (long) rc);
printf("final top: %ld\n", (long) duk_get_top(ctx));
return 0;
}
示例14: test_2b
int test_2b(duk_context *ctx) {
duk_set_top(ctx, 0);
duk_push_null(ctx);
duk_to_object(ctx, 0);
printf("index 0 OK\n");
return 0;
}
示例15: convert_to_context
JNIEXPORT jobject JNICALL Java_com_furture_react_DuktapeEngine_nativeCallJs
(JNIEnv *env, jobject thisObject, jlong ptr, jstring jsTarget, jstring jsMethod, jobjectArray args){
duk_context *ctx = convert_to_context(ptr);
jboolean iscopy = JNI_FALSE;
const char* targetName = ((*env)->GetStringUTFChars(env, jsTarget, &iscopy));
DEBUG_LOG("ScriptEngine","Java_com_furture_react_DuktapeEngine_nativeCallJs call on %s", targetName);
duk_push_global_object(ctx);
if(duk_get_prop_string(ctx, -1, targetName)){
const char* methodName = ((*env)->GetStringUTFChars(env, jsMethod, &iscopy));
duk_push_string(ctx, methodName);
jsize length = duk_push_java_object_array(ctx, env, args);
DEBUG_LOG("ScriptEngine","Java_com_furture_react_DuktapeEngine_nativeCallJs call Function %d", length);
if(duk_pcall_prop(ctx, -2 - length, length) != DUK_EXEC_SUCCESS){
LOGE("ScriptEngine","ScriptEngine CallJS %s.%s() method %s", targetName, methodName, duk_js_error_to_string(ctx, -1));
duk_pop(ctx);
duk_push_null(ctx);
}
(*env)->ReleaseStringUTFChars(env, jsTarget, targetName);
(*env)->ReleaseStringUTFChars(env, jsMethod, methodName);
jobject value = duk_to_java_object(ctx, env, -1);
duk_pop_2(ctx);
return value;
}
(*env)->ReleaseStringUTFChars(env, jsTarget, targetName);
duk_pop_2(ctx);
return NULL;
}