summaryrefslogtreecommitdiff
path: root/src/struct-sequence.zig
blob: bc1b8e715bce25c9bfc6140d1fe0e442357ac8d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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);
    }
};