当前位置: 首页>>代码示例>>C++>>正文


C++ duk_dup函数代码示例

本文整理汇总了C++中duk_dup函数的典型用法代码示例。如果您正苦于以下问题:C++ duk_dup函数的具体用法?C++ duk_dup怎么用?C++ duk_dup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了duk_dup函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: duk_to_java_object

/**
 *
 * performance tips
 * https://www.ibm.com/developerworks/library/j-jni/
 * */
jobject duk_to_java_object(duk_context *ctx, JNIEnv*  env, int i){
	int type = duk_get_type(ctx, i);
	if(type == DUK_TYPE_BOOLEAN){
		jboolean value = duk_to_boolean(ctx, i);
		DEBUG_LOG("ScriptEngine","invoke_java_method call, convert %d args to boolean %d", i, value);
		jmethodID methodID = (*env)->GetMethodID(env, java_boolean_class, "<init>", "(Z)V");
		jobject booleanObject = (*env)->NewObject(env, java_boolean_class, methodID, value);
		return  booleanObject;
	}else if(type == DUK_TYPE_NUMBER){
		jdouble value = duk_to_number(ctx, i);
		jclass doubleClass = (*env)->FindClass(env, "java/lang/Double");
		jmethodID methodID = (*env)->GetMethodID(env, doubleClass, "<init>", "(D)V");
		jobject numberObject = (*env)->NewObject(env, doubleClass, methodID, value);
		(*env)->DeleteLocalRef(env, doubleClass);
		DEBUG_LOG("ScriptEngine","invoke_java_method call, convert %d args to number %f", i, value);
		return numberObject;
	 }else if(type == DUK_TYPE_STRING){
		    const char*  chs = duk_to_string(ctx, i);
		    DEBUG_LOG("ScriptEngine","invoke_java_method call, convert %d args to string %s", i, chs);
		   return (*env)->NewStringUTF(env, chs);
	  }else if(type == DUK_TYPE_OBJECT){
		  if(duk_get_prop_string(ctx, i, JAVA_OBJECT_MARK)){
			    DEBUG_LOG("ScriptEngine","invoke_java_method call, convert %d args to java object", i);
		  		jobject  value = duk_to_pointer(ctx, -1);
		  	    duk_pop(ctx);
		  	    return (*env)->NewLocalRef(env, value);
		  }else{
			  duk_pop(ctx);
			  if(duk_get_prop_string(ctx, i, JS_REF_MARK)){
				  DEBUG_LOG("ScriptEngine","reuse javascript object's JSRef");
				  jweak  weakRef = duk_to_pointer(ctx, -1);
				  jobject jsRefObject = (*env)->NewLocalRef(env, weakRef);
				  duk_pop(ctx);
				  if(jsRefObject != NULL){
					  return jsRefObject;
				  }
			  }else{
				  duk_pop(ctx);
			  }
			  duk_dup(ctx, i);
			  jint ref = duk_js_ref(ctx);
			  if(ref != 0){
				  DEBUG_LOG("ScriptEngine","convert javascript object to JSRef Ref Value %d ", ref);
				  jobject engine = get_engine_from_context(ctx);
				  DEBUG_LOG("ScriptEngine","convert javascript object to JSRef Ref Value");
				  jobject jsRefObject = (*env)->NewObject(env, js_ref_class, js_ref_new_method, engine, ref);
				  jweak jsWeakRef = (*env)->NewWeakGlobalRef(env, jsRefObject);
				  duk_dup(ctx, i);
				  duk_push_pointer(ctx, jsWeakRef);
				  duk_put_prop_string(ctx, -2, JS_REF_MARK);
				  duk_pop(ctx);
				  DEBUG_LOG("ScriptEngine","convert javascript object to JSRef Ref Value Success");
				  return jsRefObject;
			  }
			  return NULL;
		  }
	  }
	  DEBUG_LOG("ScriptEngine","invoke_java_method call, unhandled type convert %d args to null %s", i, duk_to_string(ctx, i));
	  return NULL;
}
开发者ID:ewrfedf,项目名称:DuktapeJava,代码行数:65,代码来源:DuktapeEngine.c

示例2: duk__push_module_object

static void duk__push_module_object(duk_context *ctx, const char *id, duk_bool_t main) {
	duk_push_object(ctx);

	/* Set this as the main module, if requested */
	if (main) {
		duk_push_global_stash(ctx);
		duk_dup(ctx, -2);
		duk_put_prop_string(ctx, -2, "\xff" "mainModule");
		duk_pop(ctx);
	}

	/* Node.js uses the canonicalized filename of a module for both module.id
	 * and module.filename.  We have no concept of a file system here, so just
	 * use the module ID for both values.
	 */
	duk_push_string(ctx, id);
	duk_dup(ctx, -1);
	duk_put_prop_string(ctx, -3, "filename");
	duk_put_prop_string(ctx, -2, "id");

	/* module.exports = {} */
	duk_push_object(ctx);
	duk_put_prop_string(ctx, -2, "exports");

	/* module.loaded = false */
	duk_push_false(ctx);
	duk_put_prop_string(ctx, -2, "loaded");

	/* module.require */
	duk__push_require_function(ctx, id);
	duk_put_prop_string(ctx, -2, "require");
}
开发者ID:davidluca3000,项目名称:vscp_software,代码行数:32,代码来源:duk_module_node.c

示例3: dukky_svg_element___proto

duk_ret_t dukky_svg_element___proto(duk_context *ctx)
{
	/* Add read/write property */
	duk_dup(ctx, 0);
	duk_push_string(ctx, "style");
	duk_push_c_function(ctx, dukky_svg_element_style_getter, 0);
	duk_push_c_function(ctx, dukky_svg_element_style_setter, 1);
	duk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER |
		DUK_DEFPROP_HAVE_SETTER |
		DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE |
		DUK_DEFPROP_HAVE_CONFIGURABLE);
	duk_pop(ctx);

	/* Set the destructor */
	duk_dup(ctx, 0);
	duk_push_c_function(ctx, dukky_svg_element___destructor, 1);
	duk_set_finalizer(ctx, -2);
	duk_pop(ctx);

	/* Set the constructor */
	duk_dup(ctx, 0);
	duk_push_c_function(ctx, dukky_svg_element___constructor, 1);
	duk_put_prop_string(ctx, -2, "\xFF\xFFNETSURF_DUKTAPE_INIT");
	duk_pop(ctx);

	return 1; /* The prototype object */
}
开发者ID:EyMenZ,项目名称:NetSurf-OS3,代码行数:27,代码来源:svg_element.c

示例4: test_uncovered

/* It's not an error for the underlying plain buffer to be too small to
 * cover the slice.  This is allowed because it may happen for dynamic
 * and external buffers at run time anyway.  In any case, no memory
 * unsafe behavior happens.
 */
static duk_ret_t test_uncovered(duk_context *ctx, void *udata) {
	(void) udata;

	duk_push_fixed_buffer(ctx, 256);
	duk_push_buffer_object(ctx, -1, 7, 512, DUK_BUFOBJ_UINT32ARRAY);

	duk_eval_string(ctx, "dumpBufferInfo");
	duk_dup(ctx, -2);
	duk_call(ctx, 1);
	duk_pop(ctx);

	duk_eval_string(ctx,
		"(function (v) {\n"
		"    for (var i = 0; i < v.length; i++) { v[i] = 123; }\n"
		"    for (var i = 0; i < v.length; i++) { var ignore = v[i]; }\n"
		"})");
	duk_dup(ctx, -2);
	duk_call(ctx, 1);
	duk_pop(ctx);

	duk_pop_n(ctx, 2);

	printf("final top: %ld\n", (long) duk_get_top(ctx));
	return 0;
}
开发者ID:jmptrader,项目名称:duktape,代码行数:30,代码来源:test-push-buffer-object.c

示例5: duk__call_prop_prep_stack

/* Prepare value stack for a method call through an object property.
 * May currently throw an error e.g. when getting the property.
 */
DUK_LOCAL void duk__call_prop_prep_stack(duk_context *ctx, duk_idx_t normalized_obj_idx, duk_idx_t nargs) {
	DUK_ASSERT_CTX_VALID(ctx);

	DUK_DDD(DUK_DDDPRINT("duk__call_prop_prep_stack, normalized_obj_idx=%ld, nargs=%ld, stacktop=%ld",
	                     (long) normalized_obj_idx, (long) nargs, (long) duk_get_top(ctx)));

	/* [... key arg1 ... argN] */

	/* duplicate key */
	duk_dup(ctx, -nargs - 1);  /* Note: -nargs alone would fail for nargs == 0, this is OK */
	duk_get_prop(ctx, normalized_obj_idx);

	DUK_DDD(DUK_DDDPRINT("func: %!T", (duk_tval *) duk_get_tval(ctx, -1)));

	/* [... key arg1 ... argN func] */

	duk_replace(ctx, -nargs - 2);

	/* [... func arg1 ... argN] */

	duk_dup(ctx, normalized_obj_idx);
	duk_insert(ctx, -nargs - 1);

	/* [... func this arg1 ... argN] */
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:28,代码来源:duk_api_call.c

示例6: _gum_duk_push_proxy

void
_gum_duk_push_proxy (duk_context * ctx,
                     duk_idx_t target,
                     duk_c_function getter,
                     duk_c_function setter)
{
  duk_dup (ctx, target);

  duk_get_global_string (ctx, "Proxy");
  duk_dup (ctx, -2);
  duk_push_object (ctx);

  if (getter != NULL)
  {
    duk_push_c_function (ctx, getter, 3);
    duk_put_prop_string (ctx, -2, "get");
  }

  if (setter != NULL)
  {
    duk_push_c_function (ctx, setter, 4);
    duk_put_prop_string (ctx, -2, "set");
  }

  duk_new (ctx, 2);

  duk_swap_top (ctx, -2);
  duk_pop (ctx);
}
开发者ID:TechLord-Forever,项目名称:frida-gum,代码行数:29,代码来源:gumdukvalue.c

示例7: _gum_duk_create_subclass

void
_gum_duk_create_subclass (duk_context * ctx,
                          const gchar * parent,
                          const gchar * name,
                          duk_c_function constructor,
                          gint constructor_nargs,
                          duk_c_function finalize)
{
  duk_push_global_object (ctx);
  duk_get_prop_string (ctx, -1, "Object");
  duk_get_prop_string (ctx, -1, "create");

  duk_get_prop_string (ctx, -3, parent);
  duk_get_prop_string (ctx, -1, "prototype");
  duk_dup (ctx, -3);
  duk_dup (ctx, -2);
  duk_call (ctx, 1);

  if (constructor != NULL)
    duk_push_c_function (ctx, constructor, constructor_nargs);
  else
    duk_push_object (ctx);

  duk_dup (ctx, -2);
  if (finalize != NULL)
  {
    duk_push_c_function (ctx, finalize, 2);
    duk_set_finalizer (ctx, -2);
  }
  duk_put_prop_string (ctx, -2, "prototype");
  duk_put_prop_string (ctx, -7, name);
  duk_pop_n (ctx, 6);
}
开发者ID:TechLord-Forever,项目名称:frida-gum,代码行数:33,代码来源:gumdukvalue.c

示例8: Component_SetProperty

static duk_ret_t Component_SetProperty(duk_context* ctx)
{
    /* 'this' binding: handler
     * [0]: target
     * [1]: key
     * [2]: val
     * [3]: receiver (proxy)
     */
    const char* attrName = duk_to_string(ctx, 1);
    if (attrName && attrName[0] >= 'a' && attrName[0] <= 'z')
    {
        IComponent* comp = GetWeakObject<IComponent>(ctx, 0);
        if (comp)
        {
            IAttribute* attr = comp->AttributeById(String(attrName));
            AssignAttributeValue(ctx, 2, attr, AttributeChange::Default);
            return 1;
        }
    }

    // Fallthrough to ordinary properties
    duk_dup(ctx, 1);
    duk_dup(ctx, 2);
    duk_put_prop(ctx, 0);
    duk_push_true(ctx);
    return 1;
}
开发者ID:realXtend,项目名称:tundra-urho3d,代码行数:27,代码来源:BindingsHelpers.cpp

示例9: dukky_before_unload_event___proto

duk_ret_t dukky_before_unload_event___proto(duk_context *ctx)
{
	/* Set this prototype's prototype (left-parent) */
	/* get prototype */
	duk_get_global_string(ctx, dukky_magic_string_prototypes);
	duk_get_prop_string(ctx, -1, "\xFF\xFFNETSURF_DUKTAPE_PROTOTYPE_EVENT");
	duk_replace(ctx, -2);
	duk_set_prototype(ctx, 0);

	/* Add read/write property */
	duk_dup(ctx, 0);
	duk_push_string(ctx, "returnValue");
	duk_push_c_function(ctx, dukky_before_unload_event_returnValue_getter, 0);
	duk_push_c_function(ctx, dukky_before_unload_event_returnValue_setter, 1);
	duk_def_prop(ctx, -4, DUK_DEFPROP_HAVE_GETTER |
		DUK_DEFPROP_HAVE_SETTER |
		DUK_DEFPROP_HAVE_ENUMERABLE | DUK_DEFPROP_ENUMERABLE |
		DUK_DEFPROP_HAVE_CONFIGURABLE);
	duk_pop(ctx);

	/* Set the destructor */
	duk_dup(ctx, 0);
	duk_push_c_function(ctx, dukky_before_unload_event___destructor, 1);
	duk_set_finalizer(ctx, -2);
	duk_pop(ctx);

	/* Set the constructor */
	duk_dup(ctx, 0);
	duk_push_c_function(ctx, dukky_before_unload_event___constructor, 2);
	duk_put_prop_string(ctx, -2, "\xFF\xFFNETSURF_DUKTAPE_INIT");
	duk_pop(ctx);

	return 1; /* The prototype object */
}
开发者ID:EyMenZ,项目名称:NetSurf-OS3,代码行数:34,代码来源:before_unload_event.c

示例10: test_varmap

/* _Varmap is preserved if function needs it. */
static duk_ret_t test_varmap(duk_context *ctx) {
	/* Get access to _Varmap by creating a function that provides
	 * an 'eval service' in a function scope.
	 */
	duk_compile_string(ctx, DUK_COMPILE_FUNCTION,
		"function (code) {\n"
		"    var foo = 123;\n"
		"    eval(code);\n"
		"}");
	duk_dump_function(ctx);
	duk_load_function(ctx);

	duk_dup(ctx, -1);
	duk_push_string(ctx, "print('hello world');");
	duk_call(ctx, 1);
	duk_pop(ctx);

	/* Eval code will use GETVAR to read 'foo', and _Varmap is
	 * needed for that.
	 */

	duk_dup(ctx, -1);
	duk_push_string(ctx, "print(foo);");
	duk_call(ctx, 1);
	duk_pop(ctx);

	duk_pop(ctx);

	printf("final top: %ld\n", (long) duk_get_top(ctx));
	return 0;
}
开发者ID:nivertech,项目名称:duktape,代码行数:32,代码来源:test-dump-load-basic.c

示例11: 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;
}
开发者ID:black13,项目名称:duktape_games,代码行数:60,代码来源:test-to-buffer.cpp

示例12: test_is_prototype_of

static duk_ret_t test_is_prototype_of(duk_context *ctx, void *udata) {
	(void) udata;

	prep(ctx);

	/* obj0.isPrototypeOf(dummy) -> false, traverses prototype chain of dummy */
	duk_eval_string(ctx, "Object.prototype.isPrototypeOf");
	duk_dup(ctx, 0);
	duk_push_object(ctx);
	duk_call_method(ctx, 1);
	printf("Object.prototype.isPrototypeOf result: %s\n", duk_safe_to_string(ctx, -1));
	duk_pop(ctx);

	/* obj0.isPrototypeOf(obj1) -> true, traverses prototype chain of obj1 */
	duk_eval_string(ctx, "Object.prototype.isPrototypeOf");
	duk_dup(ctx, 0);
	duk_dup(ctx, 1);
	duk_call_method(ctx, 1);
	printf("Object.prototype.isPrototypeOf result: %s\n", duk_safe_to_string(ctx, -1));
	duk_pop(ctx);

	/* dummy.isPrototypeOf(obj0) -> traverses prototype chain of obj0 and throws */
	duk_eval_string(ctx, "Object.prototype.isPrototypeOf");
	duk_push_object(ctx);
	duk_dup(ctx, 0);
	duk_call_method(ctx, 1);
	printf("Object.prototype.isPrototypeOf result: %s\n", duk_safe_to_string(ctx, -1));
	duk_pop(ctx);

	return 0;
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:31,代码来源:test-dev-prototype-loop.c

示例13: duk__console_log_helper

static duk_ret_t duk__console_log_helper(duk_context *ctx, const char *error_name) {
	duk_idx_t i, n;

	n = duk_get_top(ctx);

	duk_get_global_string(ctx, "console");
	duk_get_prop_string(ctx, -1, "format");

	for (i = 0; i < n; i++) {
		if (duk_check_type_mask(ctx, i, DUK_TYPE_MASK_OBJECT)) {
			/* Slow path formatting. */
			duk_dup(ctx, -1);  /* console.format */
			duk_dup(ctx, i);
			duk_call(ctx, 1);
			duk_replace(ctx, i);  /* arg[i] = console.format(arg[i]); */
		}
	}

	duk_pop_2(ctx);

	duk_push_string(ctx, " ");
	duk_insert(ctx, 0);
	duk_join(ctx, n);

	if (error_name) {
		duk_push_error_object(ctx, DUK_ERR_ERROR, "%s", duk_require_string(ctx, -1));
		duk_push_string(ctx, "name");
		duk_push_string(ctx, error_name);
		duk_def_prop(ctx, -3, DUK_DEFPROP_FORCE | DUK_DEFPROP_HAVE_VALUE);  /* to get e.g. 'Trace: 1 2 3' */
		duk_get_prop_string(ctx, -1, "stack");
	}

	printf("%s\n", duk_to_string(ctx, -1));
	return 0;
}
开发者ID:oleavr,项目名称:duktape,代码行数:35,代码来源:duk_console.c

示例14: 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);
	}
}
开发者ID:BpLife,项目名称:duktape,代码行数:25,代码来源:test-push-this.c

示例15: duk__eval_module_source

static duk_int_t duk__eval_module_source(duk_context *ctx, void *udata) {
#else
static duk_int_t duk__eval_module_source(duk_context *ctx) {
#endif
	/*
	 *  Stack: [ ... module source ]
	 */

#if DUK_VERSION >= 19999
	(void) udata;
#endif

	/* Wrap the module code in a function expression.  This is the simplest
	 * way to implement CommonJS closure semantics and matches the behavior of
	 * e.g. Node.js.
	 */
	duk_push_string(ctx, "(function(exports,require,module,__filename,__dirname){");
	duk_dup(ctx, -2);  /* source */
	duk_push_string(ctx, "})");
	duk_concat(ctx, 3);

	/* [ ... module source func_src ] */

	(void) duk_get_prop_string(ctx, -3, "filename");
	duk_compile(ctx, DUK_COMPILE_EVAL);
	duk_call(ctx, 0);

	/* [ ... module source func ] */

	/* Set name for the wrapper function. */
	duk_push_string(ctx, "name");
	duk_push_string(ctx, "main");
	duk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_FORCE);

	/* call the function wrapper */
	(void) duk_get_prop_string(ctx, -3, "exports");   /* exports */
	(void) duk_get_prop_string(ctx, -4, "require");   /* require */
	duk_dup(ctx, -5);                                 /* module */
	(void) duk_get_prop_string(ctx, -6, "filename");  /* __filename */
	duk_push_undefined(ctx);                          /* __dirname */
	duk_call(ctx, 5);

	/* [ ... module source result(ignore) ] */

	/* module.loaded = true */
	duk_push_true(ctx);
	duk_put_prop_string(ctx, -4, "loaded");

	/* [ ... module source retval ] */

	duk_pop_2(ctx);

	/* [ ... module ] */

	return 1;
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:56,代码来源:duk_module_node.c


注:本文中的duk_dup函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。