I see some posts here example that older versions of zig allowed to retrieve function names via @typeInfo but I try to do it and there are only field names…
const anon = struct {
tte: u32,
pub fn ttr() void {}
};
const stripped = stripNamespace(anon);
pub fn main() !void {
stripped.r(); // just to force evaluation of sstripped var
}
// needs to strip the `tt` prefix
fn stripNamespace(comptime space: type) type {
const info = @typeInfo(space).@"struct";
// @as(usize, 1)
@compileLog(info.decl_names.len);
// There are no entries for functions
// @as([:0]const u8, "ttr"[0..3])
for (info.decl_names) |name| {
@compileLog(name);
}
return @TypeOf(info); // stub
}
Note the result is the same with field_names and decl_names. As far as I understand (from reading old posts and docs) field_names must really contain only field names while decl_names should be a superset of field_names and contain also functions and other stuff? (I am not sure what other stuff it could be except functions). And if this understanding is correct (unlikely) it means a compiler bug?