diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-09-02 08:17:42 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-09-02 08:17:42 +0200 |
| commit | 6c2e06ed20cdea1a67629554d8aa1d5fcda030f9 (patch) | |
| tree | e5fa1f199a35e455917f661a62b38505afa703d7 /src/struct-sequence.zig | |
| parent | 804204db7cf1e8a28defd359d17fa72949e13eff (diff) | |
Implement sequences and tuples
Diffstat (limited to 'src/struct-sequence.zig')
| -rw-r--r-- | src/struct-sequence.zig | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/struct-sequence.zig b/src/struct-sequence.zig new file mode 100644 index 0000000..bc1b8e7 --- /dev/null +++ b/src/struct-sequence.zig @@ -0,0 +1,25 @@ +const c = @import("c"); + +const zpy = @import("root.zig"); + +pub const StructSequence = extern struct { + const Self = @This(); + + data: c.PyObject, + + pub fn new(t: *zpy.Type) !*Self { + return @ptrCast(c.PyStructSequence_New(@ptrCast(@constCast(t))) orelse return error.Exception); + } + + pub fn get(self: *Self, index: usize) *Self { + return @ptrCast(c.PyStructSequence_GetItem(@ptrCast(self), @intCast(index))); + } + + pub fn set(self: *Self, index: usize, value: *zpy.Object) void { + c.PyStructSequence_SetItem(@ptrCast(self), @intCast(index), @ptrCast(value)); + } + + pub fn asObject(self: *Self) *zpy.Object { + return @ptrCast(self); + } +}; |