pkg/objc starting

This commit is contained in:
Mitchell Hashimoto
2022-10-25 16:21:11 -07:00
parent e7ffb823af
commit dd8fde52d9
5 changed files with 42 additions and 0 deletions

10
pkg/objc/build.zig Normal file
View File

@@ -0,0 +1,10 @@
const std = @import("std");
pub const pkg = std.build.Pkg{
.name = "objc",
.source = .{ .path = thisDir() ++ "/main.zig" },
};
fn thisDir() []const u8 {
return std.fs.path.dirname(@src().file) orelse ".";
}

4
pkg/objc/c.zig Normal file
View File

@@ -0,0 +1,4 @@
pub usingnamespace @cImport({
@cInclude("objc/runtime.h");
@cInclude("objc/message.h");
});

20
pkg/objc/class.zig Normal file
View File

@@ -0,0 +1,20 @@
const std = @import("std");
const c = @import("c.zig");
pub const Class = struct {
value: c.Class,
/// Returns the class definition of a specified class.
pub fn getClass(name: [:0]const u8) ?Class {
return Class{
.value = c.objc_getClass(name.ptr) orelse return null,
};
}
};
test {
const testing = std.testing;
const NSObject = Class.getClass("NSObject");
try testing.expect(NSObject != null);
try testing.expect(Class.getClass("NoWay") == null);
}

6
pkg/objc/main.zig Normal file
View File

@@ -0,0 +1,6 @@
pub const c = @import("c.zig");
pub usingnamespace @import("class.zig");
test {
@import("std").testing.refAllDecls(@This());
}