Add NSBundle, NSError, NSEnumerator

This commit is contained in:
gingerBill
2022-02-09 12:19:59 +00:00
parent 5f2514db63
commit 768c2684d0
5 changed files with 275 additions and 3 deletions

View File

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

View File

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

View File

@@ -24,4 +24,10 @@ Dictionary_objectForKey :: proc(self: ^Dictionary, key: ^Object) -> ^Object {
return msgSend(^Dictionary, self, "objectForKey:", key)
}
// TODO(bill): enumerator
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")
}

View File

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

View File

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