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

View File

@ -11,6 +11,7 @@ const libxml2 = @import("vendor/zig-libxml2/libxml2.zig");
const libuv = @import("pkg/libuv/build.zig");
const libpng = @import("pkg/libpng/build.zig");
const macos = @import("pkg/macos/build.zig");
const objc = @import("pkg/objc/build.zig");
const stb_image_resize = @import("pkg/stb_image_resize/build.zig");
const utf8proc = @import("pkg/utf8proc/build.zig");
const zlib = @import("pkg/zlib/build.zig");
@ -194,6 +195,7 @@ fn addDeps(
step.addPackage(imgui.pkg);
step.addPackage(glfw.pkg);
step.addPackage(libuv.pkg);
step.addPackage(objc.pkg);
step.addPackage(stb_image_resize.pkg);
step.addPackage(utf8proc.pkg);

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());
}