Skip to content

Commit

Permalink
Remove c.zig and dual namespacing
Browse files Browse the repository at this point in the history
We don't really need @cImport. And dual namespacing (e.g., foundation.ns
or quartz_core.ca) just increases verbosity.
  • Loading branch information
mjbshaw authored and slimsag committed Aug 21, 2024
1 parent 00e4d86 commit 7c4333c
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 54 deletions.
1 change: 0 additions & 1 deletion app_kit_manual.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const c = @import("c.zig");
const ca = @import("quartz_core.zig");
const cf = @import("core_foundation.zig");
const ns = @import("foundation.zig");
Expand Down
1 change: 0 additions & 1 deletion avf_audio_manual.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const c = @import("c.zig");
const cf = @import("core_foundation.zig");
const ns = @import("foundation.zig");
const objc = @import("objc.zig");
Expand Down
1 change: 0 additions & 1 deletion core_midi_manual.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const c = @import("c.zig");
const cf = @import("core_foundation.zig");
const ns = @import("foundation.zig");

Expand Down
2 changes: 1 addition & 1 deletion generator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ fn Generator(comptime WriterType: type) type {
if (container.super) |super| {
try self.generateContainerName(super);
} else {
try self.writer.writeAll("c.object_type");
try self.writer.writeAll("objc.Id");
}
try self.writer.writeAll(", &.{");
} else {
Expand Down
1 change: 0 additions & 1 deletion metal_manual.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const c = @import("c.zig");
const cf = @import("core_foundation.zig");
const ns = @import("foundation.zig");
const objc = @import("objc.zig");
Expand Down
3 changes: 1 addition & 2 deletions src/app_kit.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const c = @import("c.zig");
const ca = @import("quartz_core.zig");
const cf = @import("core_foundation.zig");
const ns = @import("foundation.zig");
Expand Down Expand Up @@ -159,7 +158,7 @@ pub const Notification = opaque {
};

pub const ObjectInterface = opaque {
pub const InternalInfo = objc.ExternClass("NSObject", @This(), c.object_type, &.{});
pub const InternalInfo = objc.ExternClass("NSObject", @This(), objc.Id, &.{});
pub const as = InternalInfo.as;
pub const retain = InternalInfo.retain;
pub const release = InternalInfo.release;
Expand Down
1 change: 0 additions & 1 deletion src/avf_audio.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const c = @import("c.zig");
const cf = @import("core_foundation.zig");
const ns = @import("foundation.zig");
const objc = @import("objc.zig");
Expand Down
5 changes: 0 additions & 5 deletions src/c.zig

This file was deleted.

1 change: 0 additions & 1 deletion src/core_midi.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const c = @import("c.zig");
const cf = @import("core_foundation.zig");
const ns = @import("foundation.zig");

Expand Down
57 changes: 19 additions & 38 deletions src/main.zig
Original file line number Diff line number Diff line change
@@ -1,49 +1,30 @@
const std = @import("std");
const c = @import("c.zig");
pub const objc = @import("objc.zig");

pub const avf_audio = struct {
pub const avaudio = @import("avf_audio.zig");
};

pub const core_foundation = struct {
pub const cf = @import("core_foundation.zig");
};

pub const core_graphics = struct {
pub const cg = @import("core_graphics.zig");
};

pub const foundation = struct {
pub const ns = @import("foundation.zig");
};

pub const metal = struct {
pub const mtl = @import("metal.zig");
};

pub const quartz_core = struct {
pub const ca = @import("quartz_core.zig");
};

pub const app_kit = struct {
pub const ns = @import("app_kit.zig");
};
// TODO: delete `appkit` once Mach is using `app_kit`.
pub const appkit = app_kit;
pub const objc = @import("objc.zig");
pub const avf_audio = @import("avf_audio.zig");
pub const core_foundation = @import("core_foundation.zig");
pub const core_graphics = @import("core_graphics.zig");
pub const foundation = @import("foundation.zig");
pub const metal = @import("metal.zig");
pub const quartz_core = @import("quartz_core.zig");
pub const app_kit = @import("app_kit.zig");

pub const mach = struct {
pub const AppDelegate = opaque {
pub fn allocInit() *AppDelegate {
return objc_alloc_init(c.objc_getClass("MACHAppDelegate").?);
}
extern "objc" fn objc_alloc_init(class: *anyopaque) *AppDelegate;

pub fn setRunBlock(self: *AppDelegate, block: *foundation.ns.Block(fn () void)) void {
pub const InternalInfo = objc.ExternClass("MACHAppDelegate", @This(), foundation.ObjectInterface, &.{app_kit.ApplicationDelegate});
pub const as = InternalInfo.as;
pub const retain = InternalInfo.retain;
pub const release = InternalInfo.release;
pub const autorelease = InternalInfo.autorelease;
pub const new = InternalInfo.new;
pub const alloc = InternalInfo.alloc;
pub const allocInit = InternalInfo.allocInit;

pub fn setRunBlock(self: *AppDelegate, block: *foundation.Block(fn () void)) void {
method(self, block);
}
const method = @extern(
*const fn (*AppDelegate, *foundation.ns.Block(fn () void)) callconv(.C) void,
*const fn (*AppDelegate, *foundation.Block(fn () void)) callconv(.C) void,
.{ .name = "\x01-[MACHAppDelegate setRunBlock:]" },
);
};
Expand Down
1 change: 0 additions & 1 deletion src/metal.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const c = @import("c.zig");
const cf = @import("core_foundation.zig");
const ns = @import("foundation.zig");
const objc = @import("objc.zig");
Expand Down
1 change: 1 addition & 0 deletions src/objc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub const opt_new = objc_opt_new;
pub const opt_class = objc_opt_class;
pub const opt_isKindOfClass = objc_opt_isKindOfClass;

// APIs that are part of libobjc's public API.
pub const Class = opaque {};
pub const Id = opaque {
pub const InternalInfo = struct {
Expand Down
1 change: 0 additions & 1 deletion src/quartz_core.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const c = @import("c.zig");
const cg = @import("core_graphics.zig");
const mtl = @import("metal.zig");
const ns = @import("foundation.zig");
Expand Down

0 comments on commit 7c4333c

Please sign in to comment.