Convert *Id to any wrapped type. Shorten names for class methods
that return an instance of the class. Fix return types for Go interfaces.
This commit is contained in:
parent
57ad898945
commit
11366be6d0
|
@ -8,13 +8,13 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
n1 := ns.NSStringStringWithUTF8String(ns.CharFromString("hi there"))
|
||||
n1 := ns.NSStringWithUTF8String(ns.CharFromString("hi there"))
|
||||
c1 := n1.CapitalizedString()
|
||||
gs := c1.UTF8String().String()
|
||||
fmt.Println(gs)
|
||||
n2 := ns.NSStringStringWithUTF8String(ns.CharFromString("hi world"))
|
||||
n3 := ns.NSStringStringWithUTF8String(ns.CharFromString("ok bye"))
|
||||
a := ns.NSMutableArrayArrayWithObjects(n1,n2,n3)
|
||||
n2 := ns.NSStringWithUTF8String(ns.CharFromString("hi world"))
|
||||
n3 := ns.NSStringWithUTF8String(ns.CharFromString("ok bye"))
|
||||
a := ns.NSMutableArrayWithObjects(n1,n2,n3)
|
||||
fmt.Println("Length(a) = ",a.Count())
|
||||
fmt.Println("is n2 in a?",a.ContainsObject(n2))
|
||||
fmt.Println("is c1 in a?",a.ContainsObject(c1))
|
||||
|
@ -23,4 +23,8 @@ func main() {
|
|||
a.AddObject(n4)
|
||||
a.AddObject(n5)
|
||||
fmt.Println("Length(a) = ",a.Count())
|
||||
a2 := a.SubarrayWithRange(ns.NSMakeRange(1,3))
|
||||
fmt.Println("Length(a2) = ",a2.Count())
|
||||
i1 := a.ObjectAtIndex(1).NSString()
|
||||
fmt.Println(i1.UTF8String())
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ func shouldWrap(gt string) bool {
|
|||
//are dereferenced to bare interface names.
|
||||
var goInterfaces map[string]bool
|
||||
|
||||
func isGoInterface(gt string) bool {
|
||||
func IsGoInterface(gt string) bool {
|
||||
return goInterfaces[gt]
|
||||
}
|
||||
|
||||
|
@ -198,7 +198,7 @@ func _goType(ct string) string {
|
|||
ct = strings.Title(ct)
|
||||
ct = strings.ReplaceAll(ct," ","")
|
||||
ct = strings.ReplaceAll(ct,"Struct","")
|
||||
if len(ct) > 0 && ct[0] == '*' && isGoInterface(ct[1:]) {
|
||||
if len(ct) > 0 && ct[0] == '*' && IsGoInterface(ct[1:]) {
|
||||
return ct[1:]
|
||||
}
|
||||
if ct == "Id" {
|
||||
|
@ -285,14 +285,15 @@ type %s interface {
|
|||
}
|
||||
`,t.Node.Ctype(),t.BaseType().GoType(),gt)
|
||||
}
|
||||
if isGoInterface(super) {
|
||||
if IsGoInterface(super) {
|
||||
super = "Id"
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
//%s (%s)
|
||||
type %s struct { %s }
|
||||
func (o *%s) Ptr() unsafe.Pointer { return unsafe.Pointer(o) }
|
||||
`,t.Node.Ctype(),t.BaseType().GoType(),gt,super,gt)
|
||||
func (o *Id) %s() *%s { return (*%s)(unsafe.Pointer(o)) }
|
||||
`,t.Node.Ctype(),t.BaseType().GoType(),gt,super,gt,gt,gt,gt)
|
||||
}
|
||||
|
||||
func (t *Type) IsFunction() bool {
|
||||
|
@ -337,7 +338,7 @@ func GoToC(name string, pnames []string, rtype *Type, ptypes []*Type) string {
|
|||
rt := rtype.CType()
|
||||
if rt != "void" {
|
||||
rtgt := rtype.GoType()
|
||||
if isGoInterface(rtgt) {
|
||||
if IsGoInterface(rtgt) {
|
||||
rtgt = "*Id"
|
||||
}
|
||||
ret.WriteString("return (" + rtgt + ")(")
|
||||
|
@ -350,7 +351,7 @@ func GoToC(name string, pnames []string, rtype *Type, ptypes []*Type) string {
|
|||
for i := 0; i < len(pnames); i++ {
|
||||
pn,pt := pnames[i],ptypes[i]
|
||||
p := pn
|
||||
if (shouldWrap(pt.GoType()) || isGoInterface(pt.GoType())) && !pt.Variadic {
|
||||
if (shouldWrap(pt.GoType()) || IsGoInterface(pt.GoType())) && !pt.Variadic {
|
||||
p = pn + ".Ptr()"
|
||||
} else {
|
||||
switch {
|
||||
|
|
20
wrap/main.go
20
wrap/main.go
|
@ -479,10 +479,23 @@ func (w *Wrapper) _processMethod(m *Method,fun bool) {
|
|||
return
|
||||
}
|
||||
gname := strings.Title(m.Name)
|
||||
if !m.ClassMethod {
|
||||
switch {
|
||||
case !m.ClassMethod:
|
||||
gname = "(o *" + m.Class + ") " + gname
|
||||
} else {
|
||||
case m.Type.GoType() != "*" + m.Class:
|
||||
gname = m.Class + gname
|
||||
default:
|
||||
lens1 := len(m.Class)
|
||||
i := 0
|
||||
if len(gname) < len(m.Class) { i = lens1 - len(gname) }
|
||||
for ; i < lens1; i++ {
|
||||
if m.Class[i:] == gname[:lens1 - i] { break }
|
||||
}
|
||||
if lens1 - i >= len(gname) {
|
||||
gname = m.Class + gname
|
||||
} else {
|
||||
gname = m.Class + gname[lens1-i:]
|
||||
}
|
||||
}
|
||||
cname := m.Name
|
||||
if m.Class != "" {
|
||||
|
@ -495,6 +508,9 @@ func (w *Wrapper) _processMethod(m *Method,fun bool) {
|
|||
if grtype == "Void" {
|
||||
grtype = ""
|
||||
}
|
||||
if types.IsGoInterface(grtype) {
|
||||
grtype = "*Id"
|
||||
}
|
||||
w.goCode.WriteString(fmt.Sprintf(`
|
||||
//%s
|
||||
func %s(%s) %s {
|
||||
|
|
Loading…
Reference in New Issue
Block a user