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

This commit is contained in:
Greg 2019-05-07 15:17:23 -04:00
parent 8ed05fb451
commit 1c5c61308c
2 changed files with 18 additions and 0 deletions

View File

@ -35,6 +35,7 @@ func nsmgr() {
s := ns.NSStringWithGoString("") s := ns.NSStringWithGoString("")
appMenu.AddItemWithTitle(ns.NSStringWithGoString("About"), nil, s) appMenu.AddItemWithTitle(ns.NSStringWithGoString("About"), nil, s)
appMenu.AddItemWithTitle(ns.NSStringWithGoString("Preferences"), nil, s) appMenu.AddItemWithTitle(ns.NSStringWithGoString("Preferences"), nil, s)
appMenu.AddItemWithTitle(ns.NSStringWithGoString("Quit"),ns.Selector("terminate:"), ns.NSStringWithGoString("q"))
a.SetMainMenu(m1) a.SetMainMenu(m1)
fileMenu.AddItemWithTitle(ns.NSStringWithGoString("Open"), nil, s) fileMenu.AddItemWithTitle(ns.NSStringWithGoString("Open"), nil, s)
fileMenu.AddItemWithTitle(ns.NSStringWithGoString("New"), nil, s) fileMenu.AddItemWithTitle(ns.NSStringWithGoString("New"), nil, s)

View File

@ -513,6 +513,9 @@ func (w *Wrapper) processType(tp *types.Type) {
if gt == "NSEnumerator" { if gt == "NSEnumerator" {
w.EnumeratorHelpers() w.EnumeratorHelpers()
} }
if gt == "SEL" {
w.SelectorHelpers()
}
if bt.IsFunction() || bt.IsFunctionPtr() { if bt.IsFunction() || bt.IsFunctionPtr() {
return 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) { func (w *Wrapper) ProcessMethod(m *Method) {
w._processMethod(m,false) w._processMethod(m,false)
} }