aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/field.zig3
-rw-r--r--src/stack.zig10
2 files changed, 13 insertions, 0 deletions
diff --git a/src/field.zig b/src/field.zig
index e96a44a..9a12a80 100644
--- a/src/field.zig
+++ b/src/field.zig
@@ -244,6 +244,9 @@ pub const Field = struct {
if (y >= f.y and y < f.y + @intCast(i64, f.lines.items.len)) return f.lines.items[@intCast(usize, y - @intCast(i64, f.y))].get(x);
return ' ';
}
+ pub fn getSize(f: Field) [4]i64 {
+ return [4]i64{ f.x, f.y, @intCast(i64, f.lx), @intCast(i64, f.lines.items.len) };
+ }
fn init(allocator: std.mem.Allocator) !*Field {
var f = try allocator.create(Field);
errdefer allocator.destroy(f);
diff --git a/src/stack.zig b/src/stack.zig
index e02cb20..09edd2e 100644
--- a/src/stack.zig
+++ b/src/stack.zig
@@ -147,6 +147,16 @@ pub const Stack = struct {
const emptyResult2 = [_]i64{ 4, 5 };
try std.testing.expectEqualSlices(i64, empty.data.items, emptyResult2[0..]);
}
+ pub fn yCommandPick(self: *Stack, n: usize, h: usize) !void {
+ if (n > self.data.items.len) {
+ self.data.items.len = 1;
+ self.data.items[0] = 0;
+ } else {
+ const v = self.data.items[self.data.items.len - n];
+ self.data.items.len = h;
+ try self.push(v);
+ }
+ }
};
test "all" {