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/type/root.zig | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/type/root.zig (limited to 'src/type/root.zig') diff --git a/src/type/root.zig b/src/type/root.zig new file mode 100644 index 0000000..128f3d9 --- /dev/null +++ b/src/type/root.zig @@ -0,0 +1,58 @@ +const std = @import("std"); +const c = @import("c"); + +const zpy = @import("../root.zig"); + +pub const Type = extern struct { + const Self = @This(); + + data: c.PyObject, + + pub const Watcher = @import("Watcher.zig"); + + pub const Description = extern struct { + name: [*:0]const u8, + doc: ?[*:0]const u8 = null, + }; + + pub fn new(description: Description, comptime fields: []const Description) !*Self { + var c_desc: c.PyStructSequence_Desc = .{ + .name = @ptrCast(description.name), + .doc = @ptrCast(description.doc), + .fields = @ptrCast(@constCast(fields)), + .n_in_sequence = @intCast(fields.len), + }; + + return @ptrCast(c.PyStructSequence_NewType(@ptrCast(&c_desc)) orelse return error.Exception); + } + + pub fn getDict(self: *Self) *zpy.Dict { + return @ptrCast(c.PyType_GetDict(@ptrCast(self))); + } + + pub fn modified(self: *Self) void { + c.PyType_Modified(@ptrCast(self)); + } + + pub fn isGc(self: *Self) bool { + return c.PyType_IS_GC(@ptrCast(self)) != 0; + } + + pub fn isSubtype(self: *Self, target: *Self) bool { + return c.PyType_IsSubtype(@ptrCast(self), @ptrCast(target)) != 0; + } + + pub fn ready(self: *Self) !void { + if (c.PyType_Ready(@ptrCast(self)) == -1) { + return error.Exception; + } + } + + pub fn getName(self: *Self) *zpy.Str { + return @ptrCast(c.Pytype_GetName(@ptrCast(self))); + } + + pub fn asObject(self: *Self) *zpy.Object { + return @ptrCast(self); + } +}; -- cgit v1.2.3-70-g09d2