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


C++ duk_push_c_function函数代码示例

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


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

示例1: duv_loadlib

// Load a duktape C function from a shared library by path and name.
static duk_ret_t duv_loadlib(duk_context *ctx) {
  const char *name, *path;
  uv_lib_t lib;
  duk_c_function fn;

  // Check the args
  const duv_schema_entry schema[] = {
    { "path", duk_is_string },
    { "name", duk_is_string },
    { NULL, NULL }
  };

  dschema_check(ctx, schema);

  path = duk_get_string(ctx, 0);
  name = duk_get_string(ctx, 1);

  if (uv_dlopen(path, &lib)) {
    duk_error(ctx, DUK_ERR_ERROR, "Cannot load shared library %s", path);
    return 0;
  }
  if (uv_dlsym(&lib, name, (void**)&fn)) {
    duk_error(ctx, DUK_ERR_ERROR, "Unable to find %s in %s", name, path);
    return 0;
  }
  duk_push_c_function(ctx, fn, 0);
  return 1;
}
开发者ID:madanagopalt,项目名称:pxCore,代码行数:29,代码来源:rtScriptDuk.cpp

示例2: _gum_duk_process_init

void
_gum_duk_process_init (GumDukProcess * self,
                       GumDukCore * core)
{
  GumDukScope scope = GUM_DUK_SCOPE_INIT (core);
  duk_context * ctx = scope.ctx;

  self->core = core;

  duk_push_c_function (ctx, gumjs_process_construct, 0);
  duk_push_object (ctx);
  duk_put_function_list (ctx, -1, gumjs_process_functions);
  duk_push_string (ctx, GUM_SCRIPT_ARCH);
  duk_put_prop_string (ctx, -2, "arch");
  duk_push_string (ctx, GUM_SCRIPT_PLATFORM);
  duk_put_prop_string (ctx, -2, "platform");
  duk_push_uint (ctx, gum_query_page_size ());
  duk_put_prop_string (ctx, -2, "pageSize");
  duk_push_uint (ctx, GLIB_SIZEOF_VOID_P);
  duk_put_prop_string (ctx, -2, "pointerSize");
  duk_put_prop_string (ctx, -2, "prototype");
  duk_new (ctx, 0);
  _gum_duk_put_data (ctx, -1, self);
  duk_put_global_string (ctx, "Process");
}
开发者ID:TechLord-Forever,项目名称:frida-gum,代码行数:25,代码来源:gumdukprocess.c

示例3: test_1

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

	/* Lightfunc, must sanitize the address for the expect string. */
	duk_eval_string(ctx,
		"(function (v) {\n"
		"    print(String(v).replace(/light_[0-9a-fA-f_]+/, 'light_PTR'));\n"
		"})");
	duk_push_c_lightfunc(ctx, dummy_func, 0 /*nargs*/, 0 /*length*/, 0 /*magic*/);
	duk_call(ctx, 1);
	duk_pop(ctx);

	/* Function with a .name containing invalid characters.
	 *
	 * This is not currently handled very well: the .toString() output
	 * uses the name as is, which can make the output technically
	 * incorrect because it won't parse as a function.  However, the
	 * only way to create such functions is from C code so this is a
	 * minor issue.
	 */

	duk_push_c_function(ctx, dummy_func, 0 /*nargs*/);
	duk_push_string(ctx, "name");
	duk_push_string(ctx, "dummy {");
	duk_def_prop(ctx, -3, DUK_DEFPROP_HAVE_VALUE | DUK_DEFPROP_FORCE);
	printf("%s\n", duk_to_string(ctx, -1));
	duk_pop(ctx);

	printf("final top: %ld\n", (long) duk_get_top(ctx));
	return 0;
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:31,代码来源:test-dev-func-tostring.c

示例4: main

int main(int argc, const char *argv[]) {
    duk_context *ctx = NULL;

    ctx = duk_create_heap_default();
    if (!ctx) {
        printf("Failed to create a Duktape heap.\n");
        exit(1);
    }

    duk_push_global_object(ctx);
    duk_push_c_function(ctx, native_prime_check, 2 /*nargs*/);
    duk_put_prop_string(ctx, -2, "primeCheckNative");

    if (duk_peval_file(ctx, "prime.js") != 0) {
        printf("Error: %s\n", duk_safe_to_string(ctx, -1));
        goto finished;
    }
    duk_pop(ctx);  /* ignore result */

    duk_get_prop_string(ctx, -1, "primeTest");
    if (duk_pcall(ctx, 0) != 0) {
        printf("Error: %s\n", duk_safe_to_string(ctx, -1));
    }
    duk_pop(ctx);  /* ignore result */

 finished:
    duk_destroy_heap(ctx);

    exit(0);
}
开发者ID:3009420,项目名称:civetweb,代码行数:30,代码来源:primecheck.c

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

示例6: PrivatePush

    static Box * PrivatePush( duk_context * ctx, const size_t class_index, const size_t object_size, finalizer_t finalizer )
    {
        duk_push_global_object( ctx );
        duk_get_prop_string( ctx, -1, "Proxy" );
        duk_remove( ctx, -2 );

        duk_push_object( ctx );

        size_t require_size = sizeof( Box ) + object_size;

        Box * box = reinterpret_cast<Box*>( duk_push_fixed_buffer( ctx, require_size ) );
        box->ClassIndex = class_index;
        box->Finalizer = finalizer;

        duk_put_prop_string( ctx, -2, "\xFF" "Box" );

        duk_push_c_function( ctx, &internal::ClassFinalizer, 1 );
        duk_set_finalizer( ctx, -2 );

        duk_push_heap_stash( ctx );
        duk_get_prop_string( ctx, -1, "InstanceHandler" );
        duk_remove( ctx, -2 );
        duk_new( ctx, 2 );

        return box;
    }
开发者ID:crazyjul,项目名称:dukbind,代码行数:26,代码来源:dukbind.cpp

示例7: duk_import_java_class

int duk_import_java_class(duk_context *ctx){
	DEBUG_LOG("DuktapeEngine", "className duk_import_java_class");
	int n = duk_get_top(ctx);
	const char* className = duk_to_string(ctx, 0);
	const char*  shortName = NULL;
	if(n > 1){
		shortName = duk_to_string(ctx, 1);
	}else{
		shortName = strrchr(className, '.');
		shortName++;
	}
	DEBUG_LOG("DuktapeEngine", "className %s  shorName %s",className, shortName);

	duk_push_global_object(ctx);
	duk_push_c_function(ctx, duk_new_java_class,  DUK_VARARGS);

	JNIEnv *env = get_java_jni_env();
	jstring  fullClassName = (*env)->NewStringUTF(env, className);
    jobject  value =  (*env)->CallStaticObjectMethod(env, java_api_class, java_import_class_method, fullClassName);
	duk_mark_jsobject_to_java_object(ctx, -1, env, value);
    (*env)->DeleteLocalRef(env, value);
	(*env)->DeleteLocalRef(env, fullClassName);
	duk_push_object(ctx);
    duk_push_string(ctx, className);
    duk_put_prop_string(ctx, -2, "className");
    duk_put_prop_string(ctx, -2, "prototype");
    duk_put_prop_string(ctx, -2, shortName);
    duk_pop(ctx);
    return 0;
}
开发者ID:ewrfedf,项目名称:DuktapeJava,代码行数:30,代码来源:DuktapeEngine.c

示例8: js_watchdog_ctor

// Constructor of the JS Object
duk_ret_t js_watchdog_ctor(duk_context *ctx)
{
    void *ptr = NULL;
    slog(DEBUG,DEBUG, "Creating new object of "PLUGIN_SCOPE);

    // Push special this binding to the function being constructed
    duk_push_this(ctx);

    // Store the underlying object
    duk_push_pointer(ctx, ptr);
    duk_put_prop_string(ctx, -2, "\xff""\xff""data");

    // TODO : - if not existand create a hash_map
    //        - store structure to a hash_map('name');
    //          so that it can be reached from JS and C
    
    // Store a boolean flag to mark the object as deleted because the destructor may be called several times
    duk_push_boolean(ctx, false);
    duk_put_prop_string(ctx, -2, "\xff""\xff""deleted");

    // Store the function destructor
    duk_push_c_function(ctx, js_watchdog_dtor, 1);
    duk_set_finalizer(ctx, -2);

    return 0;
}
开发者ID:FreshXOpenSource,项目名称:wallyd,代码行数:27,代码来源:watchdog.c

示例9: test_2

/* Thread with shared and fresh globals. */
static duk_ret_t test_2(duk_context *ctx, void *udata) {
	duk_context *ctx_a;
	duk_context *ctx_b;

	(void) udata;

	duk_eval_string_noresult(ctx, "this.globalFoo = 'bar';");

	duk_push_thread(ctx);
	ctx_a = duk_require_context(ctx, -1);
	duk_push_thread_new_globalenv(ctx);
	ctx_b = duk_require_context(ctx, -1);

	printf("top: %ld\n", (long) duk_get_top(ctx));

	/* Dummy print() binding. */
	duk_push_c_function(ctx_b, my_print, 1);
	duk_put_global_string(ctx_b, "print");

	/* index 0: thread with globals shared with 'ctx' (has globalFoo)
	 * index 1: thread with globals separate with 'ctx'
	 */

	/* Print globalFoo. */

	duk_peval_string_noresult(ctx_a, "print('context a: ' + String(this.globalFoo));");
	duk_peval_string_noresult(ctx_b, "print('context b: ' + String(this.globalFoo));");

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

示例10: PhysicsWorld_Get_Updated

static duk_ret_t PhysicsWorld_Get_Updated(duk_context* ctx)
{
    PhysicsWorld* thisObj = GetThisWeakObject<PhysicsWorld>(ctx);
    SignalWrapper_PhysicsWorld_Updated* wrapper = new SignalWrapper_PhysicsWorld_Updated(thisObj, &thisObj->Updated);
    PushValueObject(ctx, wrapper, SignalWrapper_PhysicsWorld_Updated_ID, SignalWrapper_PhysicsWorld_Updated_Finalizer, false);
    duk_push_c_function(ctx, SignalWrapper_PhysicsWorld_Updated_Connect, DUK_VARARGS);
    duk_put_prop_string(ctx, -2, "Connect");
    duk_push_c_function(ctx, SignalWrapper_PhysicsWorld_Updated_Connect, DUK_VARARGS);
    duk_put_prop_string(ctx, -2, "connect");
    duk_push_c_function(ctx, SignalWrapper_PhysicsWorld_Updated_Disconnect, DUK_VARARGS);
    duk_put_prop_string(ctx, -2, "Disconnect");
    duk_push_c_function(ctx, SignalWrapper_PhysicsWorld_Updated_Disconnect, DUK_VARARGS);
    duk_put_prop_string(ctx, -2, "disconnect");
    duk_push_c_function(ctx, SignalWrapper_PhysicsWorld_Updated_Emit, 1);
    duk_put_prop_string(ctx, -2, "Emit");
    return 1;
}
开发者ID:realXtend,项目名称:tundra-urho3d,代码行数:17,代码来源:PhysicsWorldBindings.cpp

示例11: duk_push_c_function

void Context::registerFunc(index_t idx,
                           const char* id,
                           const Function func,
                           index_t nargs)
{
    duk_push_c_function(m_handle, func, nargs);
    duk_put_prop_string(m_handle, idx, id);
}
开发者ID:Censacrof,项目名称:aseprite,代码行数:8,代码来源:engine.cpp

示例12: Avatar_Get_ParentEntitySet

static duk_ret_t Avatar_Get_ParentEntitySet(duk_context* ctx)
{
    Avatar* thisObj = GetThisWeakObject<Avatar>(ctx);
    SignalWrapper_Avatar_ParentEntitySet* wrapper = new SignalWrapper_Avatar_ParentEntitySet(thisObj, &thisObj->ParentEntitySet);
    PushValueObject(ctx, wrapper, SignalWrapper_Avatar_ParentEntitySet_ID, SignalWrapper_Avatar_ParentEntitySet_Finalizer, false);
    duk_push_c_function(ctx, SignalWrapper_Avatar_ParentEntitySet_Connect, DUK_VARARGS);
    duk_put_prop_string(ctx, -2, "Connect");
    duk_push_c_function(ctx, SignalWrapper_Avatar_ParentEntitySet_Connect, DUK_VARARGS);
    duk_put_prop_string(ctx, -2, "connect");
    duk_push_c_function(ctx, SignalWrapper_Avatar_ParentEntitySet_Disconnect, DUK_VARARGS);
    duk_put_prop_string(ctx, -2, "Disconnect");
    duk_push_c_function(ctx, SignalWrapper_Avatar_ParentEntitySet_Disconnect, DUK_VARARGS);
    duk_put_prop_string(ctx, -2, "disconnect");
    duk_push_c_function(ctx, SignalWrapper_Avatar_ParentEntitySet_Emit, 0);
    duk_put_prop_string(ctx, -2, "Emit");
    return 1;
}
开发者ID:realXtend,项目名称:tundra-urho3d,代码行数:17,代码来源:AvatarBindings.cpp

示例13: Avatar_Get_ComponentNameChanged

static duk_ret_t Avatar_Get_ComponentNameChanged(duk_context* ctx)
{
    Avatar* thisObj = GetThisWeakObject<Avatar>(ctx);
    SignalWrapper_Avatar_ComponentNameChanged* wrapper = new SignalWrapper_Avatar_ComponentNameChanged(thisObj, &thisObj->ComponentNameChanged);
    PushValueObject(ctx, wrapper, SignalWrapper_Avatar_ComponentNameChanged_ID, SignalWrapper_Avatar_ComponentNameChanged_Finalizer, false);
    duk_push_c_function(ctx, SignalWrapper_Avatar_ComponentNameChanged_Connect, DUK_VARARGS);
    duk_put_prop_string(ctx, -2, "Connect");
    duk_push_c_function(ctx, SignalWrapper_Avatar_ComponentNameChanged_Connect, DUK_VARARGS);
    duk_put_prop_string(ctx, -2, "connect");
    duk_push_c_function(ctx, SignalWrapper_Avatar_ComponentNameChanged_Disconnect, DUK_VARARGS);
    duk_put_prop_string(ctx, -2, "Disconnect");
    duk_push_c_function(ctx, SignalWrapper_Avatar_ComponentNameChanged_Disconnect, DUK_VARARGS);
    duk_put_prop_string(ctx, -2, "disconnect");
    duk_push_c_function(ctx, SignalWrapper_Avatar_ComponentNameChanged_Emit, 2);
    duk_put_prop_string(ctx, -2, "Emit");
    return 1;
}
开发者ID:realXtend,项目名称:tundra-urho3d,代码行数:17,代码来源:AvatarBindings.cpp

示例14: duk_push_global_object

void Engine::registerFunction(const char* id, Function function, int nargs)
{
  ContextHandle handle = m_ctx.handle();

  duk_push_global_object(handle);
  duk_push_c_function(handle, function, nargs);
  duk_put_prop_string(handle, -2, id);
}
开发者ID:Doraenmon,项目名称:aseprite,代码行数:8,代码来源:engine.cpp

示例15: dukky_html_menu_element___proto

duk_ret_t dukky_html_menu_element___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_HTMLELEMENT");
	duk_replace(ctx, -2);
	duk_set_prototype(ctx, 0);

	/* Add read/write property */
	duk_dup(ctx, 0);
	duk_push_string(ctx, "type");
	duk_push_c_function(ctx, dukky_html_menu_element_type_getter, 0);
	duk_push_c_function(ctx, dukky_html_menu_element_type_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);

	/* Add read/write property */
	duk_dup(ctx, 0);
	duk_push_string(ctx, "label");
	duk_push_c_function(ctx, dukky_html_menu_element_label_getter, 0);
	duk_push_c_function(ctx, dukky_html_menu_element_label_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);

	/* Add read/write property */
	duk_dup(ctx, 0);
	duk_push_string(ctx, "compact");
	duk_push_c_function(ctx, dukky_html_menu_element_compact_getter, 0);
	duk_push_c_function(ctx, dukky_html_menu_element_compact_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_html_menu_element___destructor, 1);
	duk_set_finalizer(ctx, -2);
	duk_pop(ctx);

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

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


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