• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ duk_pcall函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test

void test(duk_context *ctx) {
	duk_idx_t i, funcidx, argcount;
	duk_ret_t rc;

	/* test C function arg count variants */

	duk_push_c_function(ctx, my_int_adder, 0);              /* [0] = c func with 0 args */
	duk_push_c_function(ctx, my_int_adder, 1);              /* [1] = c func with 1 arg */
	duk_push_c_function(ctx, my_int_adder, 2);              /* [2] = c func with 2 args */
	duk_push_c_function(ctx, my_int_adder, DUK_VARARGS);    /* [3] = c func with varargs */

	for (funcidx = 0; funcidx < 4; funcidx++) {
		for (argcount = 0; argcount < 5; argcount++) {
			duk_dup(ctx, funcidx);
			for (i = 0; i < argcount; i++) {
				duk_push_int(ctx, i + 1);   /* 1, 2, 3, ... */
			}

			/* [ ... func <args> ] */
			duk_call(ctx, argcount);

			printf("funcidx=%ld, argcount=%ld -> result=%ld\n",
			       (long) funcidx, (long) argcount, (long) duk_to_int(ctx, -1));
			duk_pop(ctx);
		}
	}

	/* test C function return value 0 and negative */

	duk_set_top(ctx, 0);
	duk_push_c_function(ctx, my_zero_ret, 0);
	duk_call(ctx, 0);
	printf("top after calling my_zero_ret: %ld, retval='%s'\n",
	       (long) duk_get_top(ctx), duk_to_string(ctx, -1));
	duk_pop(ctx);

	duk_set_top(ctx, 0);
	duk_push_c_function(ctx, my_neg_ret, 0);
	rc = duk_pcall(ctx, 0);
	printf("top after calling my_neg_ret: %ld, rc=%d, retval='%s'\n",
	       (long) duk_get_top(ctx), (int) rc, duk_to_string(ctx, -1));
	duk_pop(ctx);

	duk_set_top(ctx, 0);
	duk_push_c_function(ctx, my_type_error_ret, 0);
	rc = duk_pcall(ctx, 0);
	printf("top after calling my_type_error_ret: %ld, rc=%d, retval='%s'\n",
	       (long) duk_get_top(ctx), (int) rc, duk_to_string(ctx, -1));
	duk_pop(ctx);
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:50,代码来源:test-push-cfunc.c


示例2: logMsg

bool StyleContext::evalFilter(FunctionID _id) const {
    if (!duk_get_global_string(m_ctx, FUNC_ID)) {
        logMsg("Error: evalFilterFn - functions not initialized\n");
        return false;
    }

    if (!duk_get_prop_index(m_ctx, -1, _id)) {
        logMsg("Error: evalFilterFn - function %d not set\n", _id);
    }

    if (duk_pcall(m_ctx, 0) != 0) {
        logMsg("Error: evalFilterFn: %s\n", duk_safe_to_string(m_ctx, -1));
    }

    bool result = false;

    if (duk_is_boolean(m_ctx, -1)) {
        result = duk_get_boolean(m_ctx, -1);
    }

    // pop result
    duk_pop(m_ctx);
    // pop fns obj
    duk_pop(m_ctx);

    DUMP("evalFilterFn\n");
    return result;
}
开发者ID:xvilan,项目名称:tangram-es,代码行数:28,代码来源:styleContext.cpp


示例3: 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


示例4: LOGE

bool StyleContext::evalFunction(FunctionID id) {
    // Get all functions (array) in context
    if (!duk_get_global_string(m_ctx, FUNC_ID)) {
        LOGE("EvalFilterFn - functions array not initialized");
        duk_pop(m_ctx); // pop [undefined] sitting at stack top
        return false;
    }

    // Get function at index `id` from functions array, put it at stack top
    if (!duk_get_prop_index(m_ctx, -1, id)) {
        LOGE("EvalFilterFn - function %d not set", id);
        duk_pop(m_ctx); // pop "undefined" sitting at stack top
        duk_pop(m_ctx); // pop functions (array) now sitting at stack top
        return false;
    }

    // pop fns array
    duk_remove(m_ctx, -2);

    // call popped function (sitting at stack top), evaluated value is put on stack top
    if (duk_pcall(m_ctx, 0) != 0) {
        LOGE("EvalFilterFn: %s", duk_safe_to_string(m_ctx, -1));
        duk_pop(m_ctx);
        return false;
    }

    return true;
}
开发者ID:NabilNoaman,项目名称:tangram-es,代码行数:28,代码来源:styleContext.cpp


示例5: es_fa_read

static void
es_fa_read(void *aux)
{
  es_fa_handle_t *fah = aux;
  es_fap_t *ef = fah->fah_ef;
  es_context_t *ec = ef->super.er_ctx;
  duk_context *ctx = ec->ec_duk;

  es_context_begin(ec);

  duk_set_top(ctx, 0);

  duk_push_external_buffer(ctx);
  es_root_register(ctx, -1, fah->fah_readbuf);

  duk_config_buffer(ctx, 0, fah->fah_readbuf, fah->fah_readlen);

  es_push_root(ctx, ef);
  duk_get_prop_string(ctx, -1, "read");
  es_push_native_obj(ctx, &es_native_fah, fah_retain(fah));
  es_push_root(ctx, fah);

  duk_push_buffer_object(ctx, 0, 0, fah->fah_readlen, DUK_BUFOBJ_UINT8ARRAY);
  duk_push_int(ctx, fah->fah_readlen);
  duk_push_number(ctx, fah->fah_fpos);

  int rc = duk_pcall(ctx, 5);
  if(rc) {
    fah_exception(fah, ctx);
    es_dump_err(ctx);
  }

  es_context_end(ec, 0);
  fah_release(fah);
}
开发者ID:Ezio-PS,项目名称:movian,代码行数:35,代码来源:es_faprovider.c


示例6: es_fa_stat

static void
es_fa_stat(void *aux)
{
  es_fa_handle_t *fah = aux;
  es_fap_t *ef = fah->fah_ef;
  es_context_t *ec = ef->super.er_ctx;
  duk_context *ctx = ec->ec_duk;

  es_context_begin(ec);

  duk_set_top(ctx, 0);

  es_push_root(ctx, ef);
  duk_get_prop_string(ctx, -1, "stat");
  es_push_native_obj(ctx, &es_native_fah, fah_retain(fah));
  duk_push_string(ctx, fah->fah_url);

  int rc = duk_pcall(ctx, 2);
  if(rc) {
    fah_exception(fah, ctx);
    es_dump_err(ctx);
  }

  es_context_end(ec, 0);
  fah_release(fah);
}
开发者ID:Ezio-PS,项目名称:movian,代码行数:26,代码来源:es_faprovider.c


示例7: remapCallback

static void remapCallback(void* data, s32 x, s32 y, RemapResult* result)
{

	RemapData* remap = (RemapData*)data;
	duk_context* duk = remap->duk;

	duk_push_heapptr(duk, remap->remap);
	duk_push_int(duk, result->index);
	duk_push_int(duk, x);
	duk_push_int(duk, y);
	duk_pcall(duk, 3);

	if(duk_is_array(duk, -1))
	{
		duk_get_prop_index(duk, -1, 0);
		result->index = duk_to_int(duk, -1);
		duk_pop(duk);

		duk_get_prop_index(duk, -1, 1);
		result->flip = duk_to_int(duk, -1);
		duk_pop(duk);

		duk_get_prop_index(duk, -1, 2);
		result->rotate = duk_to_int(duk, -1);
		duk_pop(duk);
	}
	else
	{
		result->index = duk_to_int(duk, -1);		
	}

	duk_pop(duk);
}
开发者ID:rdrpenguin04,项目名称:TIC-80,代码行数:33,代码来源:jsapi.c


示例8: duk_push_global_stash

Variant DuktapeScriptFunction::call(const std::vector<Variant> & args)
{
    // Get function wrapper from stash
    duk_push_global_stash(m_context);
    duk_get_prop_index(m_context, -1, m_stashIndex);

    // Push arguments
    for (Variant var : args)
    {
        m_scriptBackend->pushToDukStack(var);
    }

    // Call function
    duk_int_t error = duk_pcall(m_context, args.size());

    // Check for error
    if (error)
    {
        // Raise script exception
        m_scriptBackend->m_scriptContext->scriptException(std::string(duk_safe_to_string(m_context, -1)));
        duk_pop_2(m_context);
        return Variant();
    }

    // Convert return value
    Variant value = m_scriptBackend->fromDukStack(-1);
    duk_pop_2(m_context);
    return value;
}
开发者ID:Beta-Alf,项目名称:cppexpose,代码行数:29,代码来源:DuktapeScriptFunction.cpp


示例9: OnSignal

 void OnSignal(Entity * param0, Entity * param1, const float3 & param2, const float3 & param3, float param4, float param5, bool param6)
 {
     duk_context* ctx = ctx_;
     duk_push_global_object(ctx);
     duk_get_prop_string(ctx, -1, "_OnSignal");
     duk_remove(ctx, -2);
     duk_push_number(ctx, (size_t)key_);
     duk_push_array(ctx);
     PushWeakObject(ctx, param0);
     duk_put_prop_index(ctx, -2, 0);
     PushWeakObject(ctx, param1);
     duk_put_prop_index(ctx, -2, 1);
     PushValueObjectCopy<float3>(ctx, param2, float3_ID, float3_Finalizer);
     duk_put_prop_index(ctx, -2, 2);
     PushValueObjectCopy<float3>(ctx, param3, float3_ID, float3_Finalizer);
     duk_put_prop_index(ctx, -2, 3);
     duk_push_number(ctx, param4);
     duk_put_prop_index(ctx, -2, 4);
     duk_push_number(ctx, param5);
     duk_put_prop_index(ctx, -2, 5);
     duk_push_boolean(ctx, param6);
     duk_put_prop_index(ctx, -2, 6);
     bool success = duk_pcall(ctx, 2) == 0;
     if (!success) LogError("[JavaScript] OnSignal: " + GetErrorString(ctx));
     duk_pop(ctx);
 }
开发者ID:realXtend,项目名称:tundra-urho3d,代码行数:26,代码来源:PhysicsWorldBindings.cpp


示例10: timer_thread

static void *
timer_thread(void *aux)
{
  int destroy = 0;
  es_timer_t *et;
  hts_mutex_lock(&timer_mutex);
  while(1) {

    et = LIST_FIRST(&timers);
    if(et == NULL)
      break;

    int64_t now = arch_get_ts();
    int64_t delta = et->et_expire - now;
    if(delta > 0) {
      int ms = (delta + 999) / 1000;
      hts_cond_wait_timeout(&timer_cond, &timer_mutex, ms);
      continue;
    }

    LIST_REMOVE(et, et_link);
    if(et->et_interval) {
      et->et_expire = now + et->et_interval * 1000LL;
      LIST_INSERT_SORTED(&timers, et, et_link, estimercmp, es_timer_t);
    } else {
      et->et_expire = 0;
      destroy = 1;
    }

    es_resource_retain(&et->super);
    hts_mutex_unlock(&timer_mutex);

    es_context_t *ec = et->super.er_ctx;
    es_context_begin(ec);

    duk_context *ctx = ec->ec_duk;

    es_push_root(ctx, et);
    int rc = duk_pcall(ctx, 0);
    if(rc)
      es_dump_err(ctx);

    duk_pop(ctx);

    es_resource_release(&et->super);

    if(destroy)
      es_resource_destroy(&et->super);

    es_context_end(ec, 0);

    hts_mutex_lock(&timer_mutex);
  }
  thread_running = 0;
  hts_mutex_unlock(&timer_mutex);
  return NULL;
}
开发者ID:Ralbarker,项目名称:showtime,代码行数:57,代码来源:es_timer.c


示例11: main

int main(int argc, const char *argv[]) {
    duk_context *ctx = NULL;
    char line[4096];
    size_t idx;
    int ch;

    (void) argc; (void) argv;

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

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

    memset(line, 0, sizeof(line));
    idx = 0;
    for (;;) {
        if (idx >= sizeof(line)) {
            printf("Line too long\n");
            exit(1);
        }

        ch = fgetc(stdin);
        if (ch == 0x0a) {
            line[idx++] = '\0';

            duk_push_global_object(ctx);
            duk_get_prop_string(ctx, -1 /*index*/, "processLine");
            duk_push_string(ctx, line);
            if (duk_pcall(ctx, 1 /*nargs*/) != 0) {
                printf("Error: %s\n", duk_safe_to_string(ctx, -1));
            } else {
                printf("%s\n", duk_safe_to_string(ctx, -1));
            }
            duk_pop(ctx);  /* pop result/error */

            idx = 0;
        } else if (ch == EOF) {
            break;
        } else {
            line[idx++] = (char) ch;
        }
    }

 finished:
    duk_destroy_heap(ctx);

    exit(0);
}
开发者ID:GarethNelson,项目名称:duktape,代码行数:56,代码来源:processlines.c


示例12: jsplugin_load

    bool jsplugin_load(JSVM* vm, const String& pluginLibrary)
    {
         String errorMsg;
         atomic_plugin_validate_function validatefunc;
         duk_c_function initfunc;

         duk_context* ctx = vm->GetJSContext();

         LOGINFOF("Loading Native Plugin: %s", pluginLibrary.CString());

         if (!jsplugin_get_entry_points(pluginLibrary, &validatefunc, &initfunc, errorMsg))
         {
             LOGERRORF("%s", errorMsg.CString());
             return false;
         }

         int version = ATOMIC_JSPLUGIN_VERSION;
         if (!validatefunc(version, &gJSVMExports, sizeof(JSVMImports)))
         {
             LOGERRORF("Native Plugin: atomic_plugin_validate failed: %s", pluginLibrary.CString());
             return false;
         }

        // just to verify that we're not doing anything funky with the stack
        int top = duk_get_top(ctx);

        // the import function is a standard duktape c function, neat
        duk_push_c_function(ctx, initfunc, 1);

        // requires exports to be at index 2
        duk_dup(ctx, 2);

        bool success = true;
        if (duk_pcall(ctx, 1) != DUK_EXEC_SUCCESS)
        {
            success = false;
            LOGERRORF("Native Plugin: error calling atomic_plugin_init %s", pluginLibrary.CString());
        }
        else
        {
            if (!duk_is_boolean(ctx, -1) || !duk_to_boolean(ctx, -1))
            {
                success = false;
                LOGERRORF("Native Plugin: error calling atomic_plugin_init, didn't return true %s", pluginLibrary.CString());
            }
        }

        duk_pop(ctx);
        assert(top == duk_get_top(ctx));

        return success;


    }
开发者ID:RobertoMalatesta,项目名称:AtomicGameEngine,代码行数:54,代码来源:JSPlugin.cpp


示例13: OnSignal

 void OnSignal()
 {
     duk_context* ctx = ctx_;
     duk_push_global_object(ctx);
     duk_get_prop_string(ctx, -1, "_OnSignal");
     duk_remove(ctx, -2);
     duk_push_number(ctx, (size_t)key_);
     duk_push_array(ctx);
     bool success = duk_pcall(ctx, 2) == 0;
     if (!success) LogError("[JavaScript] OnSignal: " + GetErrorString(ctx));
     duk_pop(ctx);
 }
开发者ID:realXtend,项目名称:tundra-urho3d,代码行数:12,代码来源:TerrainBindings.cpp


示例14: CallConnectSignal

void CallConnectSignal(duk_context* ctx, void* signal)
{
    int numArgs = duk_get_top(ctx);
    duk_push_number(ctx, (size_t)signal);
    duk_insert(ctx, 0);
    duk_push_global_object(ctx);
    duk_get_prop_string(ctx, -1, "_ConnectSignal");
    duk_remove(ctx, -2); // Global object
    duk_insert(ctx, 0);
    duk_pcall(ctx, numArgs + 1);
    duk_pop(ctx);
}
开发者ID:realXtend,项目名称:tundra-urho3d,代码行数:12,代码来源:BindingsHelpers.cpp


示例15: test

void test(duk_context *ctx) {
        int rc;

        duk_eval_string(ctx, "this.testFunc = eval.bind(this, 'print(\\'hello from eval\\')');");
	duk_pop(ctx);

	duk_push_global_object(ctx);
	duk_get_prop_string(ctx, -1, "testFunc");
	rc = duk_pcall(ctx, 0);
	printf("rc=%d\n", rc);
	duk_pop_2(ctx);

        printf("final top: %d\n", duk_get_top(ctx));
}
开发者ID:alwayrun,项目名称:duktape,代码行数:14,代码来源:test-indirect-eval.c


示例16: callJavascriptOverline

static void callJavascriptOverline(tic_mem* memory, void* data)
{
	tic_machine* machine = (tic_machine*)memory;
	duk_context* duk = machine->js;

	const char* OvrFunc = ApiKeywords[2];

	if(duk_get_global_string(duk, OvrFunc)) 
	{
		if(duk_pcall(duk, 0) != 0)
			machine->data->error(machine->data->data, duk_safe_to_string(duk, -1));
	}

	duk_pop(duk);
}
开发者ID:rdrpenguin04,项目名称:TIC-80,代码行数:15,代码来源:jsapi.c


示例17: callJavascriptScanlineName

static void callJavascriptScanlineName(tic_mem* memory, s32 row, void* data, const char* name)
{
	tic_machine* machine = (tic_machine*)memory;
	duk_context* duk = machine->js;

	if(duk_get_global_string(duk, name)) 
	{
		duk_push_int(duk, row);

		if(duk_pcall(duk, 1) != 0)
			machine->data->error(machine->data->data, duk_safe_to_string(duk, -1));
	}

	duk_pop(duk);
}
开发者ID:rdrpenguin04,项目名称:TIC-80,代码行数:15,代码来源:jsapi.c


示例18: test

static duk_ret_t test(duk_context *ctx) {
	duk_ret_t rc;

	/* basic success case */
	duk_eval_string(ctx, "(function (x,y) { return x+y; })");
	duk_push_int(ctx, 10);
	duk_push_int(ctx, 11);
	rc = duk_pcall(ctx, 2);
	printf("rc=%d, result='%s'\n", (int) rc, duk_safe_to_string(ctx, -1));
	duk_pop(ctx);
	printf("top after pop: %ld\n", (long) duk_get_top(ctx));

	/* basic error case */
	duk_eval_string(ctx, "(function (x,y) { throw new Error('my error'); })");
	duk_push_int(ctx, 10);
	duk_push_int(ctx, 11);
	rc = duk_pcall(ctx, 2);
	printf("rc=%d, result='%s'\n", (int) rc, duk_safe_to_string(ctx, -1));
	duk_pop(ctx);
	printf("top after pop: %ld\n", (long) duk_get_top(ctx));

	printf("final top: %ld\n", (long) duk_get_top(ctx));
	return 0;
}
开发者ID:black13,项目名称:duktape_games,代码行数:24,代码来源:test-pcall.cpp


示例19: havefile2_helper

static duk_ret_t havefile2_helper(duk_context *ctx, duk_c_function target_func) {
	duk_int_t rc;

	target_func_hack = target_func;
	duk_push_c_function(ctx, havefile2_helper_2, 0);  /* Duktape/C func with no .fileName */
	duk_pcall(ctx, 0);
	(void) rc;

	duk_eval_string(ctx, "(function (e) { print(e.fileName, e.lineNumber); if (PRINT_STACK) { print(e.stack); } })");
	duk_dup(ctx, -2);
	duk_call(ctx, 1);
	duk_pop(ctx);

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


示例20: OnSignal

 void OnSignal(IAssetTransfer * param0, String param1)
 {
     duk_context* ctx = ctx_;
     duk_push_global_object(ctx);
     duk_get_prop_string(ctx, -1, "_OnSignal");
     duk_remove(ctx, -2);
     duk_push_number(ctx, (size_t)key_);
     duk_push_array(ctx);
     PushWeakObject(ctx, param0);
     duk_put_prop_index(ctx, -2, 0);
     duk_push_string(ctx, param1.CString());
     duk_put_prop_index(ctx, -2, 1);
     bool success = duk_pcall(ctx, 2) == 0;
     if (!success) LogError("[JavaScript] OnSignal: " + GetErrorString(ctx));
     duk_pop(ctx);
 }
开发者ID:realXtend,项目名称:tundra-urho3d,代码行数:16,代码来源:IAssetTransferBindings.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ duk_pop函数代码示例发布时间:2022-05-30
下一篇:
C++ duk_insert函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap