#Concatenating idents
1 messages ยท Page 1 of 1 (latest)
Not really. Though depending on what it is you want to accomplish there are some loose equivalents. There's the concat (++) operator, which concatenates slices and arrays with compile-time known length. So you can do stuff like "foo" ++ "bar". If you combine this with the fact that you can do @field(namespace, decl_name), you can imagine what you can manage to do
as long as you do this comptime works:
fn callLikeMacro(comptime namespace: type, comptime name1: []const u8, comptime name2: []const u8, args: anytype) @TypeOf(@field(namespace, name1 ++ name2)) {
return @call(.{}, @field(namespace, name1 ++ name2), args);
}
You can go further by checking the field is actually a function
and other bs
Fully worried but, you do what you can ๐
Reminder to close the post if done ๐
Ah yes the call is callLikeMacro(MyType, "some","world", .{});
And you pass arguments in the .{}
Three dots menu proably
remove the whole call thing to the field thing
and the return type... oh wait I think the return type is fine lol, I failed to get the true return type for the function call
My bad
It's a slightly bigger line in that one, but doesn't matter
you will discover it eventually
if not you can ask