Open kassane opened 1 year ago
input
int square = [](int num) {
return num * num;
};
output
info: binding `cxx.h`
info: transpiled 51/51 (100.00 %)
info: formating `x86_64/linux/gnu/cxx.zig`
// auto generated by c2z
const std = @import("std");
//const cpp = @import("cpp");
extern var square: c_int;
pub inline fn square() *c_int {
return □
}
input
auto square = [](auto num) {
return num * num;
};
output
info: binding `cxx.h`
error: unknow type `(lambda at cxx.h:2:15)`, falling back to `*anyopaque`
info: transpiled 56/56 (100.00 %)
info: formating `x86_64/linux/gnu/cxx.zig`
// auto generated by c2z
const std = @import("std");
//const cpp = @import("cpp");
extern var square: *anyopaque;
pub inline fn square() **anyopaque {
return □
}
error: redeclaration of 'square'
I don't think lambda is a feature that I wan't to support, but is nice to keep in mind
Just out of curiosity is there any library that shows a real use example of this?
Just out of curiosity is there any library that shows a real use example of this?
No! I don't know of any libraries that have this requirement. It is probably a very recent topic to discuss.
clang tests:
Another test
int foo(){
return [](){return 6;}();
}
Output:
// auto generated by c2z
const std = @import("std");
//const cpp = @import("cpp");
pub fn foo() c_int {
return;
}
Suggestion:
fn unammed() c_int { return 6; }
pub fn foo() c_int { return unammed(); }
or try zig callback *const fn( ) T
Reference:
Some lambda test - C++20: https://godbolt.org/z/Gq1h7Ezn9
Lambda 1
input
output
Lambda 2
input
output
References