remove usingnamespace

This commit is contained in:
Mitchell Hashimoto 2024-11-04 09:47:56 -08:00
parent 23a0e72227
commit 579beb5684
No known key found for this signature in database
GPG key ID: 523D5DC389D273BC
9 changed files with 49 additions and 24 deletions

View file

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

View file

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

View file

@ -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;

View file

@ -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.

View file

@ -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)

View file

@ -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`).

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {