mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
pkg/macos: add missing functions to macos/foundation
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const base = @import("base.zig");
|
||||
const c = @import("c.zig");
|
||||
const cftype = @import("type.zig");
|
||||
const ComparisonResult = base.ComparisonResult;
|
||||
const Range = base.Range;
|
||||
@ -42,6 +43,14 @@ pub const Array = opaque {
|
||||
};
|
||||
|
||||
pub const MutableArray = opaque {
|
||||
pub fn create() Allocator.Error!*MutableArray {
|
||||
return CFArrayCreateMutable(
|
||||
null,
|
||||
0,
|
||||
&c.kCFTypeArrayCallBacks,
|
||||
) orelse error.OutOfMemory;
|
||||
}
|
||||
|
||||
pub fn createCopy(array: *Array) Allocator.Error!*MutableArray {
|
||||
return CFArrayCreateMutableCopy(
|
||||
null,
|
||||
@ -54,6 +63,14 @@ pub const MutableArray = opaque {
|
||||
cftype.CFRelease(self);
|
||||
}
|
||||
|
||||
pub fn appendValue(
|
||||
self: *MutableArray,
|
||||
comptime Elem: type,
|
||||
value: *const Elem,
|
||||
) void {
|
||||
CFArrayAppendValue(self, @constCast(@ptrCast(value)));
|
||||
}
|
||||
|
||||
pub fn sortValues(
|
||||
self: *MutableArray,
|
||||
comptime Elem: type,
|
||||
@ -73,12 +90,20 @@ pub const MutableArray = opaque {
|
||||
);
|
||||
}
|
||||
|
||||
extern "c" fn CFArrayCreateMutable(
|
||||
allocator: ?*anyopaque,
|
||||
capacity: usize,
|
||||
callbacks: ?*const anyopaque,
|
||||
) ?*MutableArray;
|
||||
extern "c" fn CFArrayCreateMutableCopy(
|
||||
allocator: ?*anyopaque,
|
||||
capacity: usize,
|
||||
array: *Array,
|
||||
) ?*MutableArray;
|
||||
|
||||
extern "c" fn CFArrayAppendValue(
|
||||
*MutableArray,
|
||||
*anyopaque,
|
||||
) void;
|
||||
extern "c" fn CFArraySortValues(
|
||||
array: *MutableArray,
|
||||
range: Range,
|
||||
|
@ -6,8 +6,8 @@ const c = @import("c.zig");
|
||||
|
||||
pub const Dictionary = opaque {
|
||||
pub fn create(
|
||||
keys: ?[]?*const anyopaque,
|
||||
values: ?[]?*const anyopaque,
|
||||
keys: ?[]const ?*const anyopaque,
|
||||
values: ?[]const ?*const anyopaque,
|
||||
) Allocator.Error!*Dictionary {
|
||||
if (keys != null or values != null) {
|
||||
assert(keys != null);
|
||||
@ -17,8 +17,8 @@ pub const Dictionary = opaque {
|
||||
|
||||
return @as(?*Dictionary, @ptrFromInt(@intFromPtr(c.CFDictionaryCreate(
|
||||
null,
|
||||
@ptrCast(if (keys) |slice| slice.ptr else null),
|
||||
@ptrCast(if (values) |slice| slice.ptr else null),
|
||||
@constCast(@ptrCast(if (keys) |slice| slice.ptr else null)),
|
||||
@constCast(@ptrCast(if (values) |slice| slice.ptr else null)),
|
||||
@intCast(if (keys) |slice| slice.len else 0),
|
||||
&c.kCFTypeDictionaryKeyCallBacks,
|
||||
&c.kCFTypeDictionaryValueCallBacks,
|
||||
|
Reference in New Issue
Block a user