From 22a5d1617e79f176ecfca22d6c72be215f0da8b6 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 17 Jan 2026 18:40:47 +0900 Subject: implement object key access --- src/jq/execute.zig | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/jq/execute.zig') diff --git a/src/jq/execute.zig b/src/jq/execute.zig index a07204a..8e9bbb0 100644 --- a/src/jq/execute.zig +++ b/src/jq/execute.zig @@ -66,6 +66,14 @@ const ValueStack = struct { else => error.InvalidType, }; } + + pub fn popObject(self: *Self) ExecuteError!jv.Object { + const value = try self.pop(); + return switch (value) { + .object => |o| o, + else => error.InvalidType, + }; + } }; pub fn execute(allocator: std.mem.Allocator, instrs: []const Instr, input: jv.Value) !jv.Value { @@ -86,6 +94,11 @@ pub fn execute(allocator: std.mem.Allocator, instrs: []const Instr, input: jv.Va const result = if (index < array.items.len) array.items[index] else .null; try value_stack.push(result); }, + .object_key => |key| { + const obj = try value_stack.popObject(); + const result = obj.get(key) orelse .null; + try value_stack.push(result); + }, .literal => |value| { try value_stack.push(value.*); }, -- cgit v1.3-1-g0d28