From 768c2684d01ac77c7e15d4a24a48f21a8fbc8abc Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 9 Feb 2022 12:19:59 +0000 Subject: [PATCH] Add NSBundle, NSError, NSEnumerator --- core/sys/darwin/Foundation/NSArray.odin | 4 +- core/sys/darwin/Foundation/NSBundle.odin | 161 +++++++++++++++++++ core/sys/darwin/Foundation/NSDictionary.odin | 8 +- core/sys/darwin/Foundation/NSEnumerator.odin | 37 +++++ core/sys/darwin/Foundation/NSError.odin | 68 ++++++++ 5 files changed, 275 insertions(+), 3 deletions(-) create mode 100644 core/sys/darwin/Foundation/NSBundle.odin create mode 100644 core/sys/darwin/Foundation/NSEnumerator.odin create mode 100644 core/sys/darwin/Foundation/NSError.odin diff --git a/core/sys/darwin/Foundation/NSArray.odin b/core/sys/darwin/Foundation/NSArray.odin index a58543d7a..435e239a2 100644 --- a/core/sys/darwin/Foundation/NSArray.odin +++ b/core/sys/darwin/Foundation/NSArray.odin @@ -19,8 +19,8 @@ Array_objectAtIndex :: proc(self: ^Array($T), index: UInteger) -> ^Object { return msgSend(^Object, self, "objectAtIndex:", index) } -Array_object :: proc(self: ^Array($T), index: UInteger) -> ^T { - return (^T)(Array_objectAtIndex(self, index)) +Array_object :: proc(self: ^Array($T), index: UInteger) -> T { + return (T)(Array_objectAtIndex(self, index)) } Array_count :: proc(self: ^Array($T)) -> UInteger { diff --git a/core/sys/darwin/Foundation/NSBundle.odin b/core/sys/darwin/Foundation/NSBundle.odin new file mode 100644 index 000000000..375e15b65 --- /dev/null +++ b/core/sys/darwin/Foundation/NSBundle.odin @@ -0,0 +1,161 @@ +package objc_Foundation + +@(objc_class="NSBundle") +Bundle :: struct { using _: Object } + +Bundle_mainBundle :: proc() -> ^Bundle { + return msgSend(^Bundle, Bundle, "mainBundle") +} + +Bundle_bundleWithPath :: proc(path: ^String) -> ^Bundle { + return msgSend(^Bundle, Bundle, "bundleWithPath:", path) +} + +Bundle_bundleWithURL :: proc(url: ^URL) -> ^Bundle { + return msgSend(^Bundle, Bundle, "bundleWithUrl:", url) +} +Bundle_bundle :: proc{ + Bundle_bundleWithPath, + Bundle_bundleWithURL, +} + + +Bundle_initWithPath :: proc(self: ^Bundle, path: ^String) -> ^Bundle { + return msgSend(^Bundle, self, "initWithPath:", path) +} + +Bundle_initWithURL :: proc(self: ^Bundle, url: ^URL) -> ^Bundle { + return msgSend(^Bundle, self, "initWithUrl:", url) +} +Bundle_init :: proc{ + Bundle_initWithPath, + Bundle_initWithURL, +} + + +Bundle_allBundles :: proc() -> (all: ^Array(^Bundle)) { + return msgSend(type_of(all), Bundle, "allBundles") +} + +Bundle_allFrameworks :: proc() -> (all: ^Array(^Object)) { + return msgSend(type_of(all), Bundle, "allFrameworks") +} + +Bundle_load :: proc(self: ^Bundle) -> BOOL { + return msgSend(BOOL, self, "load") +} +Bundle_unload :: proc(self: ^Bundle) -> BOOL { + return msgSend(BOOL, self, "unload") +} + +Bundle_isLoaded :: proc(self: ^Bundle) -> BOOL { + return msgSend(BOOL, self, "isLoaded") +} + +Bundle_preflightAndReturnError :: proc(self: ^Bundle) -> (ok: BOOL, error: ^Error) { + ok = msgSend(BOOL, self, "preflightAndReturnError:", &error) + return +} + +Bundle_loadAndReturnError :: proc(self: ^Bundle) -> (ok: BOOL, error: ^Error) { + ok = msgSend(BOOL, self, "loadAndReturnError:", &error) + return +} + +Bundle_bundleURL :: proc(self: ^Bundle) -> ^URL { + return msgSend(^URL, self, "bundleURL") +} + +Bundle_resourceURL :: proc(self: ^Bundle) -> ^URL { + return msgSend(^URL, self, "resourceURL") +} + +Bundle_executableURL :: proc(self: ^Bundle) -> ^URL { + return msgSend(^URL, self, "executableURL") +} + +Bundle_URLForAuxiliaryExecutable :: proc(self: ^Bundle, executableName: ^String) -> ^URL { + return msgSend(^URL, self, "URLForAuxiliaryExecutable:", executableName) +} + +Bundle_privateFrameworksURL :: proc(self: ^Bundle) -> ^URL { + return msgSend(^URL, self, "privateFrameworksURL") +} + +Bundle_sharedFrameworksURL :: proc(self: ^Bundle) -> ^URL { + return msgSend(^URL, self, "sharedFrameworksURL") +} + + +Bundle_sharedSupportURL :: proc(self: ^Bundle) -> ^URL { + return msgSend(^URL, self, "sharedSupportURL") +} + +Bundle_builtInPlugInsURL :: proc(self: ^Bundle) -> ^URL { + return msgSend(^URL, self, "builtInPlugInsURL") +} + +Bundle_appStoreReceiptURL :: proc(self: ^Bundle) -> ^URL { + return msgSend(^URL, self, "appStoreReceiptURL") +} + + + + +Bundle_bundlePath :: proc(self: ^Bundle) -> ^String { + return msgSend(^String, self, "bundlePath") +} + +Bundle_resourcePath :: proc(self: ^Bundle) -> ^String { + return msgSend(^String, self, "resourcePath") +} + +Bundle_executablePath :: proc(self: ^Bundle) -> ^String { + return msgSend(^String, self, "executablePath") +} + +Bundle_PathForAuxiliaryExecutable :: proc(self: ^Bundle, executableName: ^String) -> ^String { + return msgSend(^String, self, "PathForAuxiliaryExecutable:", executableName) +} + +Bundle_privateFrameworksPath :: proc(self: ^Bundle) -> ^String { + return msgSend(^String, self, "privateFrameworksPath") +} + +Bundle_sharedFrameworksPath :: proc(self: ^Bundle) -> ^String { + return msgSend(^String, self, "sharedFrameworksPath") +} + + +Bundle_sharedSupportPath :: proc(self: ^Bundle) -> ^String { + return msgSend(^String, self, "sharedSupportPath") +} + +Bundle_builtInPlugInsPath :: proc(self: ^Bundle) -> ^String { + return msgSend(^String, self, "builtInPlugInsPath") +} + +Bundle_appStoreReceiptPath :: proc(self: ^Bundle) -> ^String { + return msgSend(^String, self, "appStoreReceiptPath") +} + +Bundle_bundleIdentifier :: proc(self: ^Bundle) -> ^String { + return msgSend(^String, self, "bundleIdentifier") +} + + +Bundle_infoDictionary :: proc(self: ^Bundle) -> ^Dictionary { + return msgSend(^Dictionary, self, "infoDictionary") +} + +Bundle_localizedInfoDictionary :: proc(self: ^Bundle) -> ^Dictionary { + return msgSend(^Dictionary, self, "localizedInfoDictionary") +} + +Bundle_objectForInfoDictionaryKey :: proc(self: ^Bundle, key: ^String) -> ^Object { + return msgSend(^Object, self, "objectForInfoDictionaryKey:", key) +} + +Bundle_localizedStringForKey :: proc(self: ^Bundle, key: ^String, value: ^String = nil, tableName: ^String = nil) -> ^String { + return msgSend(^String, self, "localizedStringForKey:value:table:", key, value, tableName) +} diff --git a/core/sys/darwin/Foundation/NSDictionary.odin b/core/sys/darwin/Foundation/NSDictionary.odin index 19ea8a491..f82b8cffd 100644 --- a/core/sys/darwin/Foundation/NSDictionary.odin +++ b/core/sys/darwin/Foundation/NSDictionary.odin @@ -24,4 +24,10 @@ Dictionary_objectForKey :: proc(self: ^Dictionary, key: ^Object) -> ^Object { return msgSend(^Dictionary, self, "objectForKey:", key) } -// TODO(bill): enumerator \ No newline at end of file +Dictionary_count :: proc(self: ^Dictionary) -> UInteger { + return msgSend(UInteger, self, "count") +} + +Dictionary_keyEnumerator :: proc(self: ^Dictionary, $KeyType: typeid) -> (enumerator: ^Enumerator(KeyType)) { + return msgSend(type_of(enumerator), self, "keyEnumerator") +} diff --git a/core/sys/darwin/Foundation/NSEnumerator.odin b/core/sys/darwin/Foundation/NSEnumerator.odin new file mode 100644 index 000000000..b6adf2b98 --- /dev/null +++ b/core/sys/darwin/Foundation/NSEnumerator.odin @@ -0,0 +1,37 @@ +package objc_Foundation + +import "core:c" +import "core:intrinsics" + +FastEnumerationState :: struct #packed { + state: c.ulong, + itemsPtr: [^]^Object, + mutationsPtr: [^]c.ulong, + extra: [5]c.ulong, +} + +@(objc_class="NSFastEnumeration") +FastEnumeration :: struct {using _: Object} + +@(objc_class="NSEnumerator") +Enumerator :: struct($T: typeid) where intrinsics.type_is_pointer(T), intrinsics.type_is_subtype_of(T, ^Object) { + using _: FastEnumeration, +} + +FastEnumeration_countByEnumerating :: proc(self: ^FastEnumeration, state: ^FastEnumerationState, buffer: [^]^Object, len: UInteger) -> UInteger { + return msgSend(UInteger, self, "countByEnumeratingWithState:objects:count:", state, buffer, len) +} + +Enumerator_nextObject :: proc(self: ^$E/Enumerator($T)) -> T { + return msgSend(T, self, "nextObject") +} + +Enumerator_allObjects :: proc(self: ^$E/Enumerator($T)) -> (all: Array(T)) { + return msgSend(type_of(all), self, "allObjects") +} + +Enumerator_iterator :: proc(self: ^$E/Enumerator($T)) -> (obj: T, ok: bool) { + obj = msgSend(T, self, "nextObject") + ok = obj != nil + return +} diff --git a/core/sys/darwin/Foundation/NSError.odin b/core/sys/darwin/Foundation/NSError.odin new file mode 100644 index 000000000..85ff5514a --- /dev/null +++ b/core/sys/darwin/Foundation/NSError.odin @@ -0,0 +1,68 @@ +package objc_Foundation + +foreign import "system:Foundation.framework" + +ErrorDomain :: ^String + +foreign Foundation { + CocoaErrorDomain: ErrorDomain + POSIXErrorDomain: ErrorDomain + OSStatusErrorDomain: ErrorDomain + MachErrorDomain: ErrorDomain +} + +ErrorUserInfoKey :: ^String + +foreign Foundation { + UnderlyingErrorKey: ErrorUserInfoKey + LocalizedDescriptionKey: ErrorUserInfoKey + LocalizedFailureReasonErrorKey: ErrorUserInfoKey + LocalizedRecoverySuggestionErrorKey: ErrorUserInfoKey + LocalizedRecoveryOptionsErrorKey: ErrorUserInfoKey + RecoveryAttempterErrorKey: ErrorUserInfoKey + HelpAnchorErrorKey: ErrorUserInfoKey + DebugDescriptionErrorKey: ErrorUserInfoKey + LocalizedFailureErrorKey: ErrorUserInfoKey + StringEncodingErrorKey: ErrorUserInfoKey + URLErrorKey: ErrorUserInfoKey + FilePathErrorKey: ErrorUserInfoKey +} + +@(objc_class="NSError") +Error :: struct { using _: Copying(Error) } + +Error_errorWithDomain :: proc(domain: ErrorDomain, code: Integer, userInfo: ^Dictionary) -> ^Error { + return msgSend(^Error, Error, "errorWithDomain:code:userInfo:", domain, code, userInfo) +} + +Error_initWithDomain :: proc(self: ^Error, domain: ErrorDomain, code: Integer, userInfo: ^Dictionary) -> ^Error { + return msgSend(^Error, self, "initWithDomain:code:userInfo:", domain, code, userInfo) +} + +Error_code :: proc(self: ^Error) -> Integer { + return msgSend(Integer, self, "code") +} + +Error_domain :: proc(self: ^Error) -> ErrorDomain { + return msgSend(ErrorDomain, self, "domain") +} + +Error_userInfo :: proc(self: ^Error) -> ^Dictionary { + return msgSend(^Dictionary, self, "userInfo") +} + +Error_localizedDescription :: proc(self: ^Error) -> ^String { + return msgSend(^String, self, "localizedDescription") +} + +Error_localizedRecoveryOptions :: proc(self: ^Error) -> (options: ^Array(^Object)) { + return msgSend(type_of(options), self, "localizedRecoveryOptions") +} + +Error_localizedRecoverySuggestion :: proc(self: ^Error) -> ^String { + return msgSend(^String, self, "localizedRecoverySuggestion") +} + +Error_localizedFailureReason :: proc(self: ^Error) -> ^String { + return msgSend(^String, self, "localizedFailureReason") +} \ No newline at end of file