diff --git a/src/c.zig b/src/c.zig index 6c3b6f0..00469a1 100644 --- a/src/c.zig +++ b/src/c.zig @@ -1,4 +1,4 @@ -pub usingnamespace @cImport({ +pub const c = @cImport({ @cInclude("objc/runtime.h"); @cInclude("objc/message.h"); }); diff --git a/src/class.zig b/src/class.zig index bb0fff6..18dd871 100644 --- a/src/class.zig +++ b/src/class.zig @@ -1,12 +1,18 @@ const std = @import("std"); const assert = std.debug.assert; -const c = @import("c.zig"); +const cpkg = @import("c.zig"); +const c = cpkg.c; +const boolResult = cpkg.boolResult; const objc = @import("main.zig"); const MsgSend = @import("msg_send.zig").MsgSend; pub const Class = struct { value: c.Class, - pub usingnamespace MsgSend(Class); + + // Implement msgSend + const msg_send = MsgSend(Class); + pub const msgSend = msg_send.msgSend; + pub const msgSendSuper = msg_send.msgSendSuper; // Returns a property with a given name of a given class. pub fn getProperty(self: Class, name: [:0]const u8) ?objc.Property { @@ -72,7 +78,7 @@ pub const Class = struct { assert(fn_info.params[0].type == c.id); assert(fn_info.params[1].type == c.SEL); const encoding = comptime objc.comptimeEncode(Fn); - return c.boolResult(@TypeOf(c.class_addMethod), c.class_addMethod( + return boolResult(@TypeOf(c.class_addMethod), c.class_addMethod( self.value, objc.sel(name).value, @ptrCast(&imp), @@ -85,7 +91,7 @@ pub const Class = struct { pub fn addIvar(self: Class, name: [:0]const u8) bool { // The return type is i8 when we're cross compiling, unsure why. const result = c.class_addIvar(self.value, name, @sizeOf(c.id), @alignOf(c.id), "@"); - return c.boolResult(@TypeOf(c.class_addIvar), result); + return boolResult(@TypeOf(c.class_addIvar), result); } }; diff --git a/src/encoding.zig b/src/encoding.zig index cbc6245..9dcb64c 100644 --- a/src/encoding.zig +++ b/src/encoding.zig @@ -1,6 +1,6 @@ const std = @import("std"); const objc = @import("main.zig"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const assert = std.debug.assert; const testing = std.testing; diff --git a/src/main.zig b/src/main.zig index 3fdbb66..16c6cf7 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,15 +1,33 @@ const std = @import("std"); -pub const c = @import("c.zig"); -pub usingnamespace @import("autorelease.zig"); -pub usingnamespace @import("block.zig"); -pub usingnamespace @import("class.zig"); -pub usingnamespace @import("encoding.zig"); -pub usingnamespace @import("iterator.zig"); -pub usingnamespace @import("object.zig"); -pub usingnamespace @import("property.zig"); -pub usingnamespace @import("protocol.zig"); -pub usingnamespace @import("sel.zig"); +const autorelease = @import("autorelease.zig"); +const block = @import("block.zig"); +const class = @import("class.zig"); +const encoding = @import("encoding.zig"); +const iterator = @import("iterator.zig"); +const object = @import("object.zig"); +const property = @import("property.zig"); +const protocol = @import("protocol.zig"); +const selpkg = @import("sel.zig"); + +pub const c = @import("c.zig").c; +pub const AutoreleasePool = autorelease.AutoreleasePool; +pub const Block = block.Block; +pub const Class = class.Class; +pub const getClass = class.getClass; +pub const getMetaClass = class.getMetaClass; +pub const allocateClassPair = class.allocateClassPair; +pub const registerClassPair = class.registerClassPair; +pub const disposeClassPair = class.disposeClassPair; +pub const Encoding = encoding.Encoding; +pub const comptimeEncode = encoding.comptimeEncode; +pub const Iterator = iterator.Iterator; +pub const Object = object.Object; +pub const Property = property.Property; +pub const Protocol = protocol.Protocol; +pub const getProtocol = protocol.getProtocol; +pub const sel = selpkg.sel; +pub const Sel = selpkg.Sel; /// This just calls the C allocator free. Some things need to be freed /// and this is how they can be freed for objc. diff --git a/src/msg_send.zig b/src/msg_send.zig index 9a8386f..b4dd69b 100644 --- a/src/msg_send.zig +++ b/src/msg_send.zig @@ -1,12 +1,10 @@ const std = @import("std"); const builtin = @import("builtin"); const assert = std.debug.assert; -const c = @import("c.zig"); +const c = @import("c.zig").c; const objc = @import("main.zig"); /// Returns a struct that implements the msgSend function for type T. -/// This is meant to be used with `usingnamespace` to add dispatch -/// capability to a type that supports it. pub fn MsgSend(comptime T: type) type { // 1. T should be a struct // 2. T should have a field "value" that can be an "id" (same size) diff --git a/src/object.zig b/src/object.zig index 2615502..6773928 100644 --- a/src/object.zig +++ b/src/object.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const objc = @import("main.zig"); const MsgSend = @import("msg_send.zig").MsgSend; const Iterator = @import("iterator.zig").Iterator; @@ -8,7 +8,10 @@ const Iterator = @import("iterator.zig").Iterator; pub const Object = struct { value: c.id, - pub usingnamespace MsgSend(Object); + // Implement msgSend + const msg_send = MsgSend(Object); + pub const msgSend = msg_send.msgSend; + pub const msgSendSuper = msg_send.msgSendSuper; /// Convert a raw "id" into an Object. id must fit the size of the /// normal C "id" type (i.e. a `usize`). diff --git a/src/property.zig b/src/property.zig index aa80481..e042306 100644 --- a/src/property.zig +++ b/src/property.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const objc = @import("main.zig"); pub const Property = extern struct { diff --git a/src/protocol.zig b/src/protocol.zig index 8efaf50..e72e170 100644 --- a/src/protocol.zig +++ b/src/protocol.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const c = @import("c.zig"); +const c = @import("c.zig").c; const objc = @import("main.zig"); pub const Protocol = extern struct { diff --git a/src/sel.zig b/src/sel.zig index 23c629f..8036961 100644 --- a/src/sel.zig +++ b/src/sel.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const c = @import("c.zig"); +const c = @import("c.zig").c; // Shorthand, equivalent to Sel.registerName pub inline fn sel(name: [:0]const u8) Sel {