----------------------------------------------------------------------- Interop: c_call_lambda — receives a lambda and calls it daslang signature: def c_call_lambda(callback : lambda<(a:int; b:float) : string>; a : int; b : float) : string Mangled: "s 0 @ i f" "0 @" — lambda (single @, captures variables) Important: when calling a lambda, the FIRST argument must be the lambda itself (it
| 80 | // [0] = lambda, [1] = int a, [2] = float b |
| 81 | // ----------------------------------------------------------------------- |
| 82 | vec4f c_call_lambda_impl(das_context * ctx, das_node * node, vec4f * args) { |
| 83 | (void)node; |
| 84 | das_lambda * lambda = das_argument_lambda(args[0]); |
| 85 | int a = das_argument_int(args[1]); |
| 86 | float b = das_argument_float(args[2]); |
| 87 | |
| 88 | printf("[C] calling lambda with (%d, %.2f)\n", a, b); |
| 89 | |
| 90 | // Lambda arguments: first is the lambda itself, then the actual args. |
| 91 | vec4f lmb_args[3]; |
| 92 | lmb_args[0] = das_result_lambda(lambda); // capture context |
| 93 | lmb_args[1] = das_result_int(a); |
| 94 | lmb_args[2] = das_result_float(b); |
| 95 | |
| 96 | vec4f ret = das_context_eval_lambda(ctx, lambda, lmb_args); |
| 97 | char * ex = das_context_get_exception(ctx); |
| 98 | if (ex) { |
| 99 | printf("[C] exception in lambda: %s\n", ex); |
| 100 | return das_result_string(NULL); |
| 101 | } |
| 102 | |
| 103 | char * str = das_argument_string(ret); |
| 104 | printf("[C] lambda returned: \"%s\"\n", str); |
| 105 | return ret; |
| 106 | } |
| 107 | |
| 108 | // ----------------------------------------------------------------------- |
| 109 | // ----------------------------------------------------------------------- |
nothing calls this directly
no test coverage detected