A few small fixes.
This commit is contained in:
parent
34fbcec965
commit
86ff14b533
|
@ -10,6 +10,15 @@ import (
|
||||||
//Shortcut for literal NSStrings
|
//Shortcut for literal NSStrings
|
||||||
var nst = ns.NSStringWithGoString
|
var nst = ns.NSStringWithGoString
|
||||||
|
|
||||||
|
func pb1() {
|
||||||
|
fmt.Println("Pushed button 1")
|
||||||
|
}
|
||||||
|
|
||||||
|
func pb2() {
|
||||||
|
fmt.Println("Pushed button 2")
|
||||||
|
a.Terminate(a)
|
||||||
|
}
|
||||||
|
|
||||||
func didFinishLaunching(n ns.NSNotification) {
|
func didFinishLaunching(n ns.NSNotification) {
|
||||||
fmt.Println("Go: did finish launching")
|
fmt.Println("Go: did finish launching")
|
||||||
fmt.Printf("Notification: %s\n",n.Name().UTF8String())
|
fmt.Printf("Notification: %s\n",n.Name().UTF8String())
|
||||||
|
@ -50,13 +59,25 @@ func didFinishLaunching(n ns.NSNotification) {
|
||||||
|
|
||||||
a.SetMainMenu(m1)
|
a.SetMainMenu(m1)
|
||||||
|
|
||||||
//add some buttons and do some layout
|
//add some custom buttons
|
||||||
|
|
||||||
//don't do this:
|
b1 := ns.GButtonAlloc()
|
||||||
//b := ns.NSButtonAlloc().InitWithFrame(ns.NSMakeRect(100,100,100,50))
|
b2 := ns.GButtonAlloc()
|
||||||
|
|
||||||
|
b1.Init()
|
||||||
|
b1.PressedCallback(pb1)
|
||||||
|
b1.SetAction(ns.Selector("pressed"))
|
||||||
|
b1.SetTarget(b1)
|
||||||
|
b1.SetTitle(nst("PUSH"))
|
||||||
|
|
||||||
|
b2.Init()
|
||||||
|
b2.PressedCallback(pb2)
|
||||||
|
b2.SetTarget(b2)
|
||||||
|
b2.SetAction(ns.Selector("pressed"))
|
||||||
|
b2.SetTitle(nst("QUIT"))
|
||||||
|
|
||||||
|
//add some layout constraints
|
||||||
|
|
||||||
b1 := ns.NSButtonWithTitle(nst("PUSH"),ns.Id{},ns.Selector(""))
|
|
||||||
b2 := ns.NSButtonWithTitle(nst("QUIT"),ns.Id{},ns.Selector("terminate:"))
|
|
||||||
b1.SetTranslatesAutoresizingMaskIntoConstraints(0)
|
b1.SetTranslatesAutoresizingMaskIntoConstraints(0)
|
||||||
b2.SetTranslatesAutoresizingMaskIntoConstraints(0)
|
b2.SetTranslatesAutoresizingMaskIntoConstraints(0)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ inputfiles:
|
||||||
|
|
||||||
classes:
|
classes:
|
||||||
- NSAutoreleasePool
|
- NSAutoreleasePool
|
||||||
- NSEnumerator
|
|
||||||
- NSString
|
- NSString
|
||||||
- NSApplication
|
- NSApplication
|
||||||
- NSWindow
|
- NSWindow
|
||||||
|
@ -13,14 +12,14 @@ classes:
|
||||||
- NSMenu
|
- NSMenu
|
||||||
- NSMenuItem
|
- NSMenuItem
|
||||||
- NSButton
|
- NSButton
|
||||||
|
- NSControl
|
||||||
- NSNotification
|
- NSNotification
|
||||||
- NSStackView
|
|
||||||
- NSLayoutConstraint
|
- NSLayoutConstraint
|
||||||
- NSDictionary
|
- NSDictionary
|
||||||
- NSArray
|
- NSArray
|
||||||
- NSObject
|
- NSObject
|
||||||
|
|
||||||
functions: [NSMake.*]
|
functions: [ NSMakeRect ]
|
||||||
|
|
||||||
enums:
|
enums:
|
||||||
- NSApplication.*
|
- NSApplication.*
|
||||||
|
@ -38,6 +37,11 @@ delegates:
|
||||||
- applicationShouldTerminateAfterLastWindowClosed
|
- applicationShouldTerminateAfterLastWindowClosed
|
||||||
- applicationDidBecomeActive
|
- applicationDidBecomeActive
|
||||||
|
|
||||||
|
subclasses:
|
||||||
|
GButton:
|
||||||
|
NSButton:
|
||||||
|
- -(void)pressed
|
||||||
|
|
||||||
frameworks: [ Foundation, AppKit ]
|
frameworks: [ Foundation, AppKit ]
|
||||||
pragma: [ clang diagnostic ignored "-Wformat-security" ]
|
pragma: [ clang diagnostic ignored "-Wformat-security" ]
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ func main() {
|
||||||
n2 := ns.NSStringAlloc()
|
n2 := ns.NSStringAlloc()
|
||||||
n2 = n2.InitWithGoString("hi world")
|
n2 = n2.InitWithGoString("hi world")
|
||||||
n3 := ns.NSStringWithGoString("ok bye")
|
n3 := ns.NSStringWithGoString("ok bye")
|
||||||
|
fmt.Printf("%s\n",n3)
|
||||||
a := ns.NSMutableArrayWithObjects(n1,n2,n3)
|
a := ns.NSMutableArrayWithObjects(n1,n2,n3)
|
||||||
fmt.Println("Length(a) = ",a.Count())
|
fmt.Println("Length(a) = ",a.Count())
|
||||||
fmt.Println("is n2 in a?",a.ContainsObject(n2))
|
fmt.Println("is n2 in a?",a.ContainsObject(n2))
|
||||||
|
@ -30,7 +31,7 @@ func main() {
|
||||||
fmt.Printf("i1 = %@\n",i1)
|
fmt.Printf("i1 = %@\n",i1)
|
||||||
fmt.Printf("i1.Ptr() = %p\n",i1.Ptr())
|
fmt.Printf("i1.Ptr() = %p\n",i1.Ptr())
|
||||||
a.ObjectEnumerator().ForIn(func(o ns.Id) bool {
|
a.ObjectEnumerator().ForIn(func(o ns.Id) bool {
|
||||||
fmt.Println(o.NSString().UTF8String())
|
fmt.Println(o.NSString())
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
s1 := ns.NSSetWithObjects(n1,n2)
|
s1 := ns.NSSetWithObjects(n1,n2)
|
||||||
|
|
|
@ -4,7 +4,7 @@ classes:
|
||||||
- ClassOne
|
- ClassOne
|
||||||
- ClassTwo
|
- ClassTwo
|
||||||
subclasses:
|
subclasses:
|
||||||
ClassThree:
|
classThree:
|
||||||
ClassTwo:
|
ClassTwo:
|
||||||
- geti1
|
- geti1
|
||||||
- -(void)myMethod1:(int)a
|
- -(void)myMethod1:(int)a
|
||||||
|
|
37
wrap/main.go
37
wrap/main.go
|
@ -664,8 +664,8 @@ func (w *Wrapper) _processType(bt *types.Type, gt string) {
|
||||||
if gt == "Char" {
|
if gt == "Char" {
|
||||||
w.CharHelpers()
|
w.CharHelpers()
|
||||||
}
|
}
|
||||||
if gt == "NSEnumerator" {
|
if gt == "NSString" {
|
||||||
w.EnumeratorHelpers()
|
w.StringHelpers()
|
||||||
}
|
}
|
||||||
if gt == "SEL" {
|
if gt == "SEL" {
|
||||||
w.SelectorHelpers()
|
w.SelectorHelpers()
|
||||||
|
@ -701,6 +701,14 @@ func (c *Char) String() string {
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Wrapper) StringHelpers() {
|
||||||
|
w.goHelpers.WriteString(`
|
||||||
|
func (o NSString) String() string {
|
||||||
|
return o.UTF8String().String()
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
func (w *Wrapper) EnumeratorHelpers() {
|
func (w *Wrapper) EnumeratorHelpers() {
|
||||||
w.goHelpers.WriteString(`
|
w.goHelpers.WriteString(`
|
||||||
func (e NSEnumerator) ForIn(f func(Id) bool) {
|
func (e NSEnumerator) ForIn(f func(Id) bool) {
|
||||||
|
@ -791,7 +799,7 @@ func (w *Wrapper) _processMethod(m *Method,fun bool) {
|
||||||
gname = strings.ReplaceAll(gname," ","")
|
gname = strings.ReplaceAll(gname," ","")
|
||||||
receiver := ""
|
receiver := ""
|
||||||
cname := m.Name
|
cname := m.Name
|
||||||
fmt.Printf("Method %s (GoClass %s)\n",cname,m.GoClass)
|
//fmt.Printf("Method %s (GoClass %s)\n",cname,m.GoClass)
|
||||||
switch {
|
switch {
|
||||||
case !m.ClassMethod:
|
case !m.ClassMethod:
|
||||||
if types.IsGoInterface(m.GoClass) {
|
if types.IsGoInterface(m.GoClass) {
|
||||||
|
@ -1016,8 +1024,9 @@ func (w *Wrapper) MethodFromSig(sig,class string) *Method {
|
||||||
|
|
||||||
func (w *Wrapper) ProcessSubclass(sname string, sc *Subclass) {
|
func (w *Wrapper) ProcessSubclass(sname string, sc *Subclass) {
|
||||||
fmt.Printf("Wrapping %s\n",sname)
|
fmt.Printf("Wrapping %s\n",sname)
|
||||||
types.Wrap(sname)
|
gname := strings.Title(sname)
|
||||||
types.SetSuper(sname,sc.Super)
|
types.Wrap(gname)
|
||||||
|
types.SetSuper(gname,sc.Super)
|
||||||
ps := map[string][]string{}
|
ps := map[string][]string{}
|
||||||
ps[sc.Super] = sc.Overrides
|
ps[sc.Super] = sc.Overrides
|
||||||
nms := make([]*Method,len(sc.NewMethods))
|
nms := make([]*Method,len(sc.NewMethods))
|
||||||
|
@ -1062,16 +1071,16 @@ func (w *Wrapper) _ProcessDelSub(dname string, ps map[string][]string, nms []*Me
|
||||||
i++
|
i++
|
||||||
var ms map[string]*Method
|
var ms map[string]*Method
|
||||||
if sub {
|
if sub {
|
||||||
|
interf := w.Interfaces[pname]
|
||||||
|
supr = interf.GoName
|
||||||
if i > 1 {
|
if i > 1 {
|
||||||
fmt.Printf("Multiple inheritance is not permitted:\n subclass %s already inherits from %s\n",dname,supr)
|
fmt.Printf("Multiple inheritance is not permitted:\n subclass %s already inherits from %s\n",dname,supr)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
interf := w.Interfaces[pname]
|
|
||||||
if interf == nil {
|
if interf == nil {
|
||||||
fmt.Printf("Failed to find interface %s for subclass %s\n",pname,dname)
|
fmt.Printf("Failed to find interface %s for subclass %s\n",pname,dname)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
supr = interf.GoName
|
|
||||||
//fmt.Printf(" subclass for %s\n",pname)
|
//fmt.Printf(" subclass for %s\n",pname)
|
||||||
ms = map[string]*Method{}
|
ms = map[string]*Method{}
|
||||||
var addmeths func(s string)
|
var addmeths func(s string)
|
||||||
|
@ -1094,6 +1103,7 @@ func (w *Wrapper) _ProcessDelSub(dname string, ps map[string][]string, nms []*Me
|
||||||
}
|
}
|
||||||
//fmt.Printf(" proto %s\n",pname)
|
//fmt.Printf(" proto %s\n",pname)
|
||||||
ms = proto.InstanceMethods
|
ms = proto.InstanceMethods
|
||||||
|
types.SetSuper(dname,"Id")
|
||||||
supr = "Id"
|
supr = "Id"
|
||||||
}
|
}
|
||||||
for gname,m := range ms {
|
for gname,m := range ms {
|
||||||
|
@ -1272,7 +1282,7 @@ func (w *Wrapper) _ProcessDelSub(dname string, ps map[string][]string, nms []*Me
|
||||||
{
|
{
|
||||||
%s[(%s*)self super_%s];
|
%s[(%s*)self super_%s];
|
||||||
}
|
}
|
||||||
`,sfp,ret,gname,strings.Join(vpnames[i]," "))
|
`,sfp,ret,dname,strings.Join(vpnames[i]," "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ccode.WriteString(fmt.Sprintf(`
|
ccode.WriteString(fmt.Sprintf(`
|
||||||
|
@ -1315,7 +1325,7 @@ func %sAlloc() %s {
|
||||||
dispitems := make([]string,len(gnames))
|
dispitems := make([]string,len(gnames))
|
||||||
sdispitems := make([]string,sms)
|
sdispitems := make([]string,sms)
|
||||||
for i,n := range gnames {
|
for i,n := range gnames {
|
||||||
if !sub {
|
if !sub || sms == 0 {
|
||||||
gtypes[i] = gtypes[i][1:]
|
gtypes[i] = gtypes[i][1:]
|
||||||
}
|
}
|
||||||
dispitems[i] = fmt.Sprintf(
|
dispitems[i] = fmt.Sprintf(
|
||||||
|
@ -1332,7 +1342,7 @@ type %sDispatch struct {
|
||||||
var %sLookup map[unsafe.Pointer]%sDispatch =
|
var %sLookup map[unsafe.Pointer]%sDispatch =
|
||||||
map[unsafe.Pointer]%sDispatch{}
|
map[unsafe.Pointer]%sDispatch{}
|
||||||
`,gname,strings.Join(dispitems,"\n"),gname,gname,gname))
|
`,gname,strings.Join(dispitems,"\n"),gname,gname,gname))
|
||||||
if sub {
|
if sub && sms > 0 {
|
||||||
gocode.WriteString(fmt.Sprintf(`
|
gocode.WriteString(fmt.Sprintf(`
|
||||||
type %sSupermethods struct {
|
type %sSupermethods struct {
|
||||||
%s
|
%s
|
||||||
|
@ -1359,7 +1369,7 @@ func (d %s) %sCallback(f func(%s)%s) {
|
||||||
earglist := []string{"o unsafe.Pointer"}
|
earglist := []string{"o unsafe.Pointer"}
|
||||||
garglist := []string{}
|
garglist := []string{}
|
||||||
gargconv := []string{}
|
gargconv := []string{}
|
||||||
if sub {
|
if sub && sms > 0 {
|
||||||
garglist = []string{"super"}
|
garglist = []string{"super"}
|
||||||
}
|
}
|
||||||
for j := 1; j < len(vnames[i]); j++ {
|
for j := 1; j < len(vnames[i]); j++ {
|
||||||
|
@ -1409,7 +1419,7 @@ func (d %s) %sCallback(f func(%s)%s) {
|
||||||
` self.Super%s`,gnames[i])
|
` self.Super%s`,gnames[i])
|
||||||
}
|
}
|
||||||
sper := ""
|
sper := ""
|
||||||
if sub && len(gnames) > 0 {
|
if sub && sms > 0 {
|
||||||
sper = fmt.Sprintf(
|
sper = fmt.Sprintf(
|
||||||
` self := (*%s)(o)
|
` self := (*%s)(o)
|
||||||
super := %sSupermethods{
|
super := %sSupermethods{
|
||||||
|
@ -1500,6 +1510,9 @@ func (w *Wrapper) Wrap(toproc []string) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
w.processType(types.NewTypeFromString(i.GoName,""))
|
w.processType(types.NewTypeFromString(i.GoName,""))
|
||||||
|
if i.Name == "NSEnumerator" {
|
||||||
|
w.EnumeratorHelpers()
|
||||||
|
}
|
||||||
gname := i.GoName
|
gname := i.GoName
|
||||||
if types.IsGoInterface(i.GoName) {
|
if types.IsGoInterface(i.GoName) {
|
||||||
gname = "Id"
|
gname = "Id"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user