| ... | @@ -374,7 +374,8 @@ fn search(comptime args: []const string, ctx: anytype) FieldSearch(@TypeOf(ctx), | ... | @@ -374,7 +374,8 @@ fn search(comptime args: []const string, ctx: anytype) FieldSearch(@TypeOf(ctx), |
| 374 | if (comptime std.mem.eql(u8, args[0], "true")) return true; | 374 | if (comptime std.mem.eql(u8, args[0], "true")) return true; |
| 375 | if (comptime std.mem.eql(u8, args[0], "false")) return false; | 375 | if (comptime std.mem.eql(u8, args[0], "false")) return false; |
| 376 | if (@typeInfo(@TypeOf(ctx)) == .optional) return search(args, ctx.?); | 376 | if (@typeInfo(@TypeOf(ctx)) == .optional) return search(args, ctx.?); |
| 377 | const f = @field(ctx, args[0]); | 377 | const arg_is_number = if (comptime extras.parseDigits(usize, args[0], 10)) |_| true else |_| false; |
| | 378 | const f = if (!arg_is_number) @field(ctx, args[0]) else ctx[comptime extras.parseDigits(usize, args[0], 10) catch unreachable]; |
| 378 | if (args.len == 1) return f; | 379 | if (args.len == 1) return f; |
| 379 | return search(args[1..], f); | 380 | return search(args[1..], f); |
| 380 | } | 381 | } |
| ... | @@ -392,6 +393,14 @@ fn Field(comptime T: type, comptime field_name: string) type { | ... | @@ -392,6 +393,14 @@ fn Field(comptime T: type, comptime field_name: string) type { |
| 392 | if (extras.isIndexable(T) and std.mem.eql(u8, field_name, "len")) { | 393 | if (extras.isIndexable(T) and std.mem.eql(u8, field_name, "len")) { |
| 393 | return usize; | 394 | return usize; |
| 394 | } | 395 | } |
| | 396 | if (extras.isTuple(T) and (if (extras.parseDigits(usize, field_name, 10)) |_| true else |_| false)) { |
| | 397 | const info = @typeInfo(T).@"struct".fields; |
| | 398 | const idx = extras.parseDigits(usize, field_name, 10) catch unreachable; |
| | 399 | return info[idx].type; |
| | 400 | } |
| | 401 | if (extras.isIndexable(T) and (if (extras.parseDigits(usize, field_name, 10)) |_| true else |_| false)) { |
| | 402 | return std.meta.Child(T); |
| | 403 | } |
| 395 | switch (@typeInfo(T)) { | 404 | switch (@typeInfo(T)) { |
| 396 | .optional => |info| return Field(info.child, field_name), | 405 | .optional => |info| return Field(info.child, field_name), |
| 397 | .pointer => |info| return Field(info.child, field_name), | 406 | .pointer => |info| return Field(info.child, field_name), |