When we created our delegate and view classes on Mac OS X, it turned out we were accidentally subclassing the metaclass (of NSObject and NSView, respectively), not the actual superclass itself. Fixed tha. This also fixed that mysterious objc_new()/[object init] not working on the delegate class problem.

This commit is contained in:
Pietro Gagliardi 2014-03-30 13:21:10 -04:00
parent 08dfb5da20
commit 8f944c7ec6
3 changed files with 6 additions and 8 deletions

View File

@ -64,10 +64,8 @@ func areaInScrollView(scrollview C.id) C.id {
func makeArea(parentWindow C.id, alternate bool) C.id { func makeArea(parentWindow C.id, alternate bool) C.id {
area := objc_alloc(_goArea) area := objc_alloc(_goArea)
println(area)
area = objc_msgSend_rect(area, _initWithFrame, area = objc_msgSend_rect(area, _initWithFrame,
0, 0, 100, 100) 0, 0, 100, 100)
println("out")
// TODO others? // TODO others?
area = newAreaScrollView(area) area = newAreaScrollView(area)
addControl(parentWindow, area) addControl(parentWindow, area)
@ -78,7 +76,7 @@ println("out")
var ( var (
_NSView = objc_getClass("NSView") _NSView = objc_getClass("NSView")
_NSView_Class = C.object_getClass(_NSView) _NSView_Class = C.Class(unsafe.Pointer(_NSView))
) )
func makeAreaClass(name string) (C.Class, error) { func makeAreaClass(name string) (C.Class, error) {

View File

@ -93,7 +93,6 @@ struct xrect objc_msgSend_stret_rect_noargs(id obj, SEL sel)
id _objc_msgSend_rect(id obj, SEL sel, int64_t x, int64_t y, int64_t w, int64_t h) id _objc_msgSend_rect(id obj, SEL sel, int64_t x, int64_t y, int64_t w, int64_t h)
{ {
printf("%s\n", class_getName(objc_getMetaClass("goArea")));
return objc_msgSend(obj, sel, OurRect()); return objc_msgSend(obj, sel, OurRect());
} }

View File

@ -64,9 +64,7 @@ func mkAppDelegate() error {
if err != nil { if err != nil {
return fmt.Errorf("error adding NSApplication delegate buttonClicked: method (to handle button clicks): %v", err) return fmt.Errorf("error adding NSApplication delegate buttonClicked: method (to handle button clicks): %v", err)
} }
// TODO using objc_new() causes a segfault; find out why appDelegate = objc_new(objc_getClass(_goAppDelegate))
// TODO make alloc followed by init (I thought NSObject provided its own init?)
appDelegate = objc_alloc(objc_getClass(_goAppDelegate))
return nil return nil
} }
@ -111,7 +109,10 @@ func appDelegate_buttonClicked(self C.id, sel C.SEL, button C.id) {
// this actually constructs the delegate class // this actually constructs the delegate class
var ( var (
_NSObject_Class = C.object_getClass(_NSObject) // objc_getClass() says it returns an id but it's actually a Class
// thanks to Psy| in irc.freenode.net/##objc
// don't call object_getClass() on this then, as I originally thought — that returns the /metaclass/ (which we don't want, and in fact I wasn't even aware we COULD subclass the metaclass directly like this)
_NSObject_Class = C.Class(unsafe.Pointer(_NSObject))
) )
func makeDelegateClass(name string) (C.Class, error) { func makeDelegateClass(name string) (C.Class, error) {