diff options
| author | Pietro Gagliardi <[email protected]> | 2014-03-01 16:56:22 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-03-01 16:56:22 -0500 |
| commit | 9b4e30ccf9b1a1dc6367b0e6950fdd74cde88922 (patch) | |
| tree | 917047497ebb1103f5ec6ec08d885ae2912e8220 /delegatetypes_darwin.go | |
| parent | 0b4e1ff24600147adb3e0de8069cb8917c9d13ea (diff) | |
Started to build a single global delegate object; now to fix issues.
Diffstat (limited to 'delegatetypes_darwin.go')
| -rw-r--r-- | delegatetypes_darwin.go | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/delegatetypes_darwin.go b/delegatetypes_darwin.go deleted file mode 100644 index 2bc3498..0000000 --- a/delegatetypes_darwin.go +++ /dev/null @@ -1,49 +0,0 @@ -// 27 february 2014 -package ui - -import ( - "fmt" - "unsafe" -) - -// #cgo LDFLAGS: -lobjc -framework Foundation -// #include <stdlib.h> -// #include "objc_darwin.h" -// /* because cgo doesn't like Nil */ -// Class NilClass = Nil; -import "C" - -var ( - _NSObject_Class = C.object_getClass(_NSObject) -) - -func makeDelegateClass(name string) (C.Class, error) { - cname := C.CString(name) - defer C.free(unsafe.Pointer(cname)) - - c := C.objc_allocateClassPair(_NSObject_Class, cname, 0) - if c == C.NilClass { - return C.NilClass, fmt.Errorf("unable to create Objective-C class %s; reason unknown", name) - } - C.objc_registerClassPair(c) - return c, nil -} - -// according to errors spit out by cgo, C function pointers are unsafe.Pointer -func addDelegateMethod(class C.Class, sel C.SEL, imp unsafe.Pointer) error { - // maps to void (*)(id, SEL, id) - ty := []C.char{'v', '@', ':', '@', 0} - - // clas methods get stored in the metaclass; the objc_allocateClassPair() docs say this will work - // metaclass := C.object_getClass(C.id(unsafe.Pointer(class))) - // we're adding instance methods, so just class will do - ok := C.class_addMethod(class, - sel, - C.IMP(imp), - &ty[0]) - if ok == C.BOOL(C.NO) { - // TODO get function name - return fmt.Errorf("unable to add selector %v/imp %v (reason unknown)", sel, imp) - } - return nil -} |
