summaryrefslogtreecommitdiff
path: root/darwintest/objc_darwin.go
diff options
context:
space:
mode:
Diffstat (limited to 'darwintest/objc_darwin.go')
-rw-r--r--darwintest/objc_darwin.go66
1 files changed, 61 insertions, 5 deletions
diff --git a/darwintest/objc_darwin.go b/darwintest/objc_darwin.go
index 79fe4d3..ce6b87b 100644
--- a/darwintest/objc_darwin.go
+++ b/darwintest/objc_darwin.go
@@ -1,16 +1,72 @@
// 28 february 2014
package main
-/*
-These are wrapper functions for the functions in bleh_darwin.m to wrap around stdint.h type casting.
-
-This will eventually be expanded to include the other Objective-C runtime support functions.
-*/
+import (
+ "unsafe"
+)
// #cgo LDFLAGS: -lobjc -framework Foundation
+// #include <stdlib.h>
// #include "objc_darwin.h"
import "C"
+func objc_getClass(class string) C.id {
+ cclass := C.CString(class)
+ defer C.free(unsafe.Pointer(cclass))
+
+ return C.objc_getClass(cclass)
+}
+
+func sel_getUid(sel string) C.SEL {
+ csel := C.CString(sel)
+ defer C.free(unsafe.Pointer(csel))
+
+ return C.sel_getUid(csel)
+}
+
+// Common Objective-C types and selectors.
+var (
+ _NSString = objc_getClass("NSString")
+
+ _alloc = sel_getUid("alloc")
+ _new = sel_getUid("new")
+ _release = sel_getUid("release")
+ _stringWithUTF8String = sel_getUid("stringWithUTF8String:")
+ _UTF8String = sel_getUid("UTF8String")
+)
+
+// some helper functions
+
+func objc_alloc(class C.id) C.id {
+ return C.objc_msgSend_noargs(class, _alloc)
+}
+
+func objc_new(class C.id) C.id {
+ return C.objc_msgSend_noargs(class, _new)
+}
+
+func objc_release(obj C.id) {
+ C.objc_msgSend_noargs(obj, _release)
+}
+
+func toNSString(str string) C.id {
+ cstr := C.CString(str)
+ defer C.free(unsafe.Pointer(cstr))
+
+ return C.objc_msgSend_str(_NSString,
+ _stringWithUTF8String,
+ cstr)
+}
+
+func fromNSString(str C.id) string {
+ cstr := C.objc_msgSend_noargs(str, _UTF8String)
+ return C.GoString((*C.char)(unsafe.Pointer(cstr)))
+}
+
+/*
+These are wrapper functions for the functions in bleh_darwin.m to wrap around stdint.h type casting.
+*/
+
func objc_msgSend_rect(obj C.id, sel C.SEL, x int, y int, w int, h int) C.id {
return C._objc_msgSend_rect(obj, sel,
C.int64_t(x), C.int64_t(y), C.int64_t(w), C.int64_t(h))