From 6c2e06ed20cdea1a67629554d8aa1d5fcda030f9 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 2 Sep 2026 08:17:42 +0200 Subject: Implement sequences and tuples --- src/tuple.zig | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/tuple.zig') diff --git a/src/tuple.zig b/src/tuple.zig index ba82003..4e53d3f 100644 --- a/src/tuple.zig +++ b/src/tuple.zig @@ -22,24 +22,37 @@ pub const Tuple = extern struct { } pub fn size(self: *const Self) usize { - return c.PyTuple_GET_SIZE(self.object.ptr); + return c.PyTuple_GET_SIZE(@ptrCast(self)); } - pub fn get(self: *Self, index: usize) !*zpy.Object { + pub fn get(self: *const Self, index: usize) !*zpy.Object { return @ptrCast( c.PyTuple_GetItem( - self.object.ptr, + @ptrCast(self), @intCast(index), ) orelse return error.Exception, ); } + pub fn getUnchecked(self: *Self, index: usize) *zpy.Object { + return @ptrCast(c.PyTuple.GET_ITEM( + @ptrCast(self), + @intCast(index), + )); + } + pub fn set(self: *Self, index: usize, value: *zpy.Object) !void { if (c.PyTuple_SetItem(@ptrCast(self), @intCast(index), @ptrCast(value)) == -1) { return error.Exception; } } + pub fn resize(self: *Self, newlen: usize) !void { + if (c._PyTuple_Resize(@ptrCast(&self), @intCast(newlen)) == -1) { + return error.Exception; + } + } + pub fn asObject(self: *Self) *zpy.Object { return @ptrCast(self); } -- cgit v1.2.3-70-g09d2