mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-05-18 11:10:22 +00:00
pkg/objc: properties
This commit is contained in:
@@ -14,6 +14,21 @@ pub const Class = struct {
|
||||
.value = c.objc_getClass(name.ptr) orelse return null,
|
||||
};
|
||||
}
|
||||
|
||||
/// Returns a property with a given name of a given class.
|
||||
pub fn getProperty(self: Class, name: [:0]const u8) ?objc.Property {
|
||||
return objc.Property{
|
||||
.value = c.class_getProperty(self.value, name.ptr) orelse return null,
|
||||
};
|
||||
}
|
||||
|
||||
/// Describes the properties declared by a class. This must be freed.
|
||||
pub fn copyPropertyList(self: Class) []objc.Property {
|
||||
var count: c_uint = undefined;
|
||||
const list = @ptrCast([*c]objc.Property, c.class_copyPropertyList(self.value, &count));
|
||||
if (count == 0) return list[0..0];
|
||||
return list[0..count];
|
||||
}
|
||||
};
|
||||
|
||||
test "getClass" {
|
||||
@@ -40,3 +55,20 @@ test "msgSend" {
|
||||
try testing.expect(obj.value != null);
|
||||
obj.msgSend(void, objc.sel("dealloc"), .{});
|
||||
}
|
||||
|
||||
test "getProperty" {
|
||||
const testing = std.testing;
|
||||
const NSObject = Class.getClass("NSObject").?;
|
||||
|
||||
try testing.expect(NSObject.getProperty("className") != null);
|
||||
try testing.expect(NSObject.getProperty("nope") == null);
|
||||
}
|
||||
|
||||
test "copyProperyList" {
|
||||
const testing = std.testing;
|
||||
const NSObject = Class.getClass("NSObject").?;
|
||||
|
||||
const list = NSObject.copyPropertyList();
|
||||
defer objc.free(list);
|
||||
try testing.expect(list.len > 20);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user