diff options
Diffstat (limited to 'src/jq/execute.zig')
| -rw-r--r-- | src/jq/execute.zig | 13 |
1 files changed, 13 insertions, 0 deletions
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.*); }, |
