Add SelectorHelpers() so you can send named selectors to Objective-C.
This commit is contained in:
parent
8ed05fb451
commit
1c5c61308c
|
@ -35,6 +35,7 @@ func nsmgr() {
|
|||
s := ns.NSStringWithGoString("")
|
||||
appMenu.AddItemWithTitle(ns.NSStringWithGoString("About"), nil, s)
|
||||
appMenu.AddItemWithTitle(ns.NSStringWithGoString("Preferences"), nil, s)
|
||||
appMenu.AddItemWithTitle(ns.NSStringWithGoString("Quit"),ns.Selector("terminate:"), ns.NSStringWithGoString("q"))
|
||||
a.SetMainMenu(m1)
|
||||
fileMenu.AddItemWithTitle(ns.NSStringWithGoString("Open"), nil, s)
|
||||
fileMenu.AddItemWithTitle(ns.NSStringWithGoString("New"), nil, s)
|
||||
|
|
17
wrap/main.go
17
wrap/main.go
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user