----------------------------------------------------------------------- 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
| 40 | // arg 2: "f" (float) |
| 41 | // ----------------------------------------------------------------------- |
| 42 | vec4f 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 |
nothing calls this directly
no test coverage detected