43 lines
963 B
C
43 lines
963 B
C
#include <stdio.h>
|
|
#include <breeze.h>
|
|
|
|
int BZ_LAMBDA_DECL(lambdaAdd, int a) {
|
|
BZ_LAMBDA_UNPACK_START();
|
|
BZ_LAMBDA_UNPACK(int, x); // still have access to x
|
|
|
|
return a + x;
|
|
}
|
|
|
|
void BZ_LAMBDA_NOP_DECL(printArgs) {
|
|
BZ_LAMBDA_UNPACK_START();
|
|
BZ_LAMBDA_UNPACK(int, argc);
|
|
BZ_LAMBDA_UNPACK(char **, argv);
|
|
|
|
printf("Program arguments:\n");
|
|
for (int i = 0; i < argc; i++) {
|
|
printf("\t%s\n", argv[i]);
|
|
}
|
|
}
|
|
|
|
BzLambda foo(int x) {
|
|
BzLambda lam = BZ_LAMBDA(lambdaAdd);
|
|
BZ_LAMBDA_BEGIN_CAPTURE(&lam);
|
|
BZ_LAMBDA_CAPTURE(&lam, x);
|
|
// x goes out of scope
|
|
return lam;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
BzLambda lambda1 = foo(8);
|
|
printf("%d\n", BZ_LAMBDA_CALL(&lambda1, int, 1));
|
|
|
|
BzLambda printLam = BZ_LAMBDA(printArgs);
|
|
BZ_LAMBDA_BEGIN_CAPTURE(&printLam);
|
|
BZ_LAMBDA_CAPTURE(&printLam, argc);
|
|
BZ_LAMBDA_CAPTURE(&printLam, argv);
|
|
BZ_LAMBDA_NOP_CALL(&printLam, void);
|
|
|
|
return 0;
|
|
}
|