#function reflection
1 messages · Page 1 of 1 (latest)
Thanks! I was able to use that to determine how to get the return type of a function. But that only gets information about the first parameter. I haven't been able to get the syntax right to iterate over all the parameters with a for loop. I get the error "error: values of type '[]const builtin.Type.Fn.Param' must be comptime-known, but index value is runtime-known". I probably need to add the comptime keyword somewhere, but haven't figured that out. Here is my code:
const T = @TypeOf(next); // next is a function
print("next type is {}\n", .{T});
const info = @typeInfo(T);
const return_type = info.Fn.return_type;
print("return type is {any}\n", .{return_type});
for (info.Fn.params) |param| {
print("param = {any}\n", .{param.type});
}
try doing an inline for