summaryrefslogtreecommitdiff
path: root/darwintest/runtimetest.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-02-28 11:06:20 -0500
committerPietro Gagliardi <[email protected]>2014-02-28 11:06:20 -0500
commit0fdfc4c7a6770799368ce943d510c51341a0227b (patch)
tree6a70a4a04a74dbd083c280c375a27cf16365630f /darwintest/runtimetest.go
parente0c351a2d7dd30c52a1067fbc5cdb6517b6eeed0 (diff)
Built a window delegate and ran the event loop. It works!
Diffstat (limited to 'darwintest/runtimetest.go')
-rw-r--r--darwintest/runtimetest.go30
1 files changed, 19 insertions, 11 deletions
diff --git a/darwintest/runtimetest.go b/darwintest/runtimetest.go
index f86398d..79138ef 100644
--- a/darwintest/runtimetest.go
+++ b/darwintest/runtimetest.go
@@ -38,10 +38,16 @@ func sel_getUid(sel string) C.SEL {
return C.sel_getUid(csel)
}
-func main() {
- sel := sel_getUid("ourMethod")
- C.objc_msgSend_noargs(mk("hello", sel),
- sel)
+var NSApp C.id
+
+func init() {
+ // need an NSApplication first - see https://github.com/TooTallNate/NodObjC/issues/21
+ NSApplication := objc_getClass("NSApplication")
+ sharedApplication := sel_getUid("sharedApplication")
+ NSApp = C.objc_msgSend_noargs(NSApplication, sharedApplication)
+
+ sel := sel_getUid("windowShouldClose:")
+ mk("hello", sel)
}
const (
@@ -61,17 +67,13 @@ const (
var alloc = sel_getUid("alloc")
-func wintest() {
+func main() {
NSWindow := objc_getClass("NSWindow")
NSWindowinit :=
sel_getUid("initWithContentRect:styleMask:backing:defer:")
+ setDelegate := sel_getUid("setDelegate:")
makeKeyAndOrderFront := sel_getUid("makeKeyAndOrderFront:")
- // need an NSApplication first - see https://github.com/TooTallNate/NodObjC/issues/21
- NSApplication := objc_getClass("NSApplication")
- sharedApplication := sel_getUid("sharedApplication")
- C.objc_msgSend_noargs(NSApplication, sharedApplication)
-
rect := C.CGRect{
origin: C.CGPoint{100, 100},
size: C.CGSize{320, 240},
@@ -82,7 +84,13 @@ func wintest() {
window := C.objc_msgSend_noargs(NSWindow, alloc)
window = C.objc_msgSend_NSRect_uint_uint_bool(window, NSWindowinit, rect, style, backing, deferx)
C.objc_msgSend_id(window, makeKeyAndOrderFront, window)
- select{}
+ delegate := C.objc_msgSend_noargs(
+ objc_getClass("hello"),
+ alloc)
+ C.objc_msgSend_id(window, setDelegate,
+ delegate)
+ C.objc_msgSend_noargs(NSApp,
+ sel_getUid("run"))
}
func helloworld() {