summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-02-28 20:53:14 -0500
committerPietro Gagliardi <[email protected]>2014-02-28 20:53:14 -0500
commite5a4f3218250f55aa7c633693012f4153eb34276 (patch)
treec7c9f690332e3d9d76889064c021e4e738b38c77
parentea24130fc82b08765173cf455f096ea0cce1fae9 (diff)
Cleaned up newtypes.go.
-rw-r--r--darwintest/newtypes.go26
-rw-r--r--darwintest/objc_darwin.go1
-rw-r--r--darwintest/runtimetest.go3
3 files changed, 15 insertions, 15 deletions
diff --git a/darwintest/newtypes.go b/darwintest/newtypes.go
index eface0d..f054a54 100644
--- a/darwintest/newtypes.go
+++ b/darwintest/newtypes.go
@@ -13,30 +13,34 @@ import (
// extern void windowShouldClose(id, SEL, id);
// extern void buttonClicked(id, SEL, id);
// extern void gotNotification(id, SEL, id);
-// /* cgo doesn't like nil or Nil */
-// extern Class NilClass; /* in runtimetest.go because of cgo limitations */
-// extern id Nilid;
+// /* because cgo doesn't like Nil */
+// extern Class NilClass; /* defined in runtimetest.go due to cgo limitations */
import "C"
-var NSObject = C.object_getClass(objc_getClass("NSObject"))
+var (
+ _NSObject_Class = C.object_getClass(_NSObject)
+)
func newClass(name string) C.Class {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
- c := C.objc_allocateClassPair(NSObject, cname, 0)
+ c := C.objc_allocateClassPair(_NSObject_Class, cname, 0)
if c == C.NilClass {
panic("unable to create Objective-C class " + name)
}
return c
}
+// TODO move these around later
+var (
+ _stop = sel_getUid("stop:")
+)
+
//export windowShouldClose
func windowShouldClose(self C.id, sel C.SEL, sender C.id) {
fmt.Println("-[hello windowShouldClose:]")
- C.objc_msgSend_id(NSApp,
- sel_getUid("stop:"),
- sender)
+ C.objc_msgSend_id(NSApp, _stop, sender)
}
//export buttonClicked
@@ -47,11 +51,7 @@ func buttonClicked(self C.id, sel C.SEL, sender C.id) {
//export gotNotification
func gotNotification(self C.id, sel C.SEL, object C.id) {
- source := (*C.char)(unsafe.Pointer(
- C.objc_msgSend_noargs(object,
- sel_getUid("UTF8String"))))
- fmt.Println("got notification from %s",
- C.GoString(source))
+ fmt.Printf("got notification from %s\n", fromNSString(object))
}
func addOurMethod(class C.Class, sel C.SEL, imp C.IMP) {
diff --git a/darwintest/objc_darwin.go b/darwintest/objc_darwin.go
index ce6b87b..524d9f7 100644
--- a/darwintest/objc_darwin.go
+++ b/darwintest/objc_darwin.go
@@ -26,6 +26,7 @@ func sel_getUid(sel string) C.SEL {
// Common Objective-C types and selectors.
var (
+ _NSObject = objc_getClass("NSObject")
_NSString = objc_getClass("NSString")
_alloc = sel_getUid("alloc")
diff --git a/darwintest/runtimetest.go b/darwintest/runtimetest.go
index 1b0b825..aafc074 100644
--- a/darwintest/runtimetest.go
+++ b/darwintest/runtimetest.go
@@ -9,8 +9,7 @@ import (
// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit
// #include <stdlib.h>
// #include "objc_darwin.h"
-// Class NilClass = Nil; /* for newtypes.go */
-// id Nilid = nil;
+// Class NilClass = Nil; /* for newtypes.go; here due to cgo limitations */
import "C"
var (