Add SelectorHelpers() so you can send named selectors to Objective-C.

This commit is contained in:
gmp
2019-05-07 15:17:23 -04:00
parent 8ed05fb451
commit 1c5c61308c
2 changed files with 18 additions and 0 deletions
+17
View File
@@ -513,6 +513,9 @@ func (w *Wrapper) processType(tp *types.Type) {
if gt == "NSEnumerator" {
w.EnumeratorHelpers()
}
if gt == "SEL" {
w.SelectorHelpers()
}
if bt.IsFunction() || bt.IsFunctionPtr() {
return
}
@@ -551,6 +554,20 @@ func (e *NSEnumerator) ForIn(f func(*Id) bool) {
`)
}
func (w *Wrapper) SelectorHelpers() {
w.cCode.WriteString(`
void*
selectorFromString(char *s) {
return NSSelectorFromString([NSString stringWithUTF8String:s]);
}
`)
w.goHelpers.WriteString(`
func Selector(s string) SEL {
return (SEL)(unsafe.Pointer(C.selectorFromString(C.CString(s))))
}
`)
}
func (w *Wrapper) ProcessMethod(m *Method) {
w._processMethod(m,false)
}