MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / c_call_function_impl

Function c_call_function_impl

tutorials/integration/c/04_callbacks.c:42–66  ·  view source on GitHub ↗

----------------------------------------------------------------------- Interop: c_call_function — receives a function pointer and calls it daslang signature: def c_call_function(callback : function<(a:int; b:float) : string>; a : int; b : float) : string Mangled: "s 0 @@ i f" return "s" (string) arg 0: "0 @@" — function pointer taking (int, float) returning string arg 1: "i" (int) arg 2

Source from the content-addressed store, hash-verified

40// arg 2: "f" (float)
41// -----------------------------------------------------------------------
42vec4f c_call_function_impl(das_context * ctx, das_node * node, vec4f * args) {
43 (void)node;
44 das_function * callback = das_argument_function(args[0]);
45 int a = das_argument_int(args[1]);
46 float b = das_argument_float(args[2]);
47
48 printf("[C] calling function pointer with (%d, %.2f)\n", a, b);
49
50 // Build arguments for the callback.
51 vec4f cb_args[2];
52 cb_args[0] = das_result_int(a);
53 cb_args[1] = das_result_float(b);
54
55 // Call the daslang function.
56 vec4f ret = das_context_eval_with_catch(ctx, callback, cb_args);
57 char * ex = das_context_get_exception(ctx);
58 if (ex) {
59 printf("[C] exception in callback: %s\n", ex);
60 return das_result_string(NULL);
61 }
62
63 char * str = das_argument_string(ret);
64 printf("[C] callback returned: \"%s\"\n", str);
65 return ret;
66}
67
68// -----------------------------------------------------------------------
69// Interop: c_call_lambda — receives a lambda and calls it

Callers

nothing calls this directly

Calls 10

das_argument_functionFunction · 0.85
das_argument_intFunction · 0.85
das_argument_floatFunction · 0.85
printfFunction · 0.85
das_result_intFunction · 0.85
das_result_floatFunction · 0.85
das_result_stringFunction · 0.85
das_argument_stringFunction · 0.85

Tested by

no test coverage detected