const std = @import("std"); const c = @import("c"); const zpy = @import("root.zig"); pub const Object = extern struct { const Self = @This(); data: c.PyObject, pub fn decref(self: *Self) void { c.Py_DecRef(@ptrCast(self)); } pub fn repr(self: *const Self) *zpy.Str { return @ptrCast(c.PyObject_Repr(@ptrCast(@constCast(self)))); } pub fn call(self: *Self, args: *zpy.Tuple, kwargs: ?*zpy.Dict) !*zpy.Object { if (c.PyObject_Call( @ptrCast(self), @ptrCast(args), @ptrCast(kwargs), )) |object| { return @ptrCast(object); } return error.Exception; } pub fn format(self: *const Self, writer: *std.Io.Writer) !void { var str = self.repr(); defer str.asObject().decref(); try writer.print("{s}", .{str.asUtf8() catch return error.WriteFailed}); } };