summaryrefslogtreecommitdiff
path: root/objc_darwin.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-04-04 21:32:10 -0400
committerPietro Gagliardi <[email protected]>2014-04-04 21:32:10 -0400
commit7ea493873cb2be2eac1e6bb08c66a119e489b38e (patch)
tree1a4dc504e7d699374c3e17752b0c3abb46629669 /objc_darwin.go
parentdd20d56f257b001fe58783e86c113c11de58ca53 (diff)
Changed the Area class on Mac OS X to use the new class creation code. This gets rid of ALL the class creation code from delegate_darwin.go.
Diffstat (limited to 'objc_darwin.go')
-rw-r--r--objc_darwin.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/objc_darwin.go b/objc_darwin.go
index 90afd74..b72dcdd 100644
--- a/objc_darwin.go
+++ b/objc_darwin.go
@@ -62,19 +62,22 @@ type selector struct {
desc string // for error reporting
}
+// sel_[returntype] or sel_[returntype]_[arguments] (after the required self/sel arguments)
type itype uint
const (
sel_void_id itype = iota
sel_bool_id
+ sel_bool
nitypes
)
var itypes = [nitypes][]C.char{
sel_void_id: []C.char{'v', '@', ':', '@', 0},
sel_bool_id: []C.char{'c', '@', ':', '@', 0},
+ sel_bool: []C.char{'c', '@', ':', 0},
}
-func makeClass(name string, super C.id, sels []selector, desc string) (err error) {
+func makeClass(name string, super C.id, sels []selector, desc string) (id C.id, class C.Class, err error) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
@@ -82,15 +85,17 @@ func makeClass(name string, super C.id, sels []selector, desc string) (err error
// thanks to Psy| in irc.freenode.net/##objc
c := C.objc_allocateClassPair(C.Class(unsafe.Pointer(super)), cname, 0)
if c == C.NilClass {
- return fmt.Errorf("unable to create Objective-C class %s for %s; reason unknown", name, desc)
+ err = fmt.Errorf("unable to create Objective-C class %s for %s; reason unknown", name, desc)
+ return
}
C.objc_registerClassPair(c)
for _, v := range sels {
ok := C.class_addMethod(c, sel_getUid(v.name),
C.IMP(unsafe.Pointer(v.imp)), &itypes[v.itype][0])
if ok == C.BOOL(C.NO) {
- return fmt.Errorf("unable to add selector %s to class %s (needed for %s; reason unknown)", v.name, name, v.desc)
+ err = fmt.Errorf("unable to add selector %s to class %s (needed for %s; reason unknown)", v.name, name, v.desc)
+ return
}
}
- return nil
+ return objc_getClass(name), c, nil
}