Return Golang bools from Objective-C functions that return BOOL.

Move nswrap command to cmd/nswrap.
This commit is contained in:
Greg 2019-05-06 09:00:38 -04:00
parent 717c7e76fe
commit 959b87342e
3 changed files with 22 additions and 4 deletions

View File

@ -167,9 +167,16 @@ func Start() (err error) {
if err != nil {
// If clang fails it still prints out the AST, so we have to run it
// again to get the real error.
// errBody, _ := exec.Command("clang", cargs...).CombinedOutput()
panic("clang failed: " + err.Error() + ":\n\n")
//errBody, _ := exec.Command("clang", cargs...).CombinedOutput()
var txt string
switch x := err.(type) {
case *exec.ExitError:
txt = string(x.Stderr)
default:
txt = err.Error()
}
fmt.Printf("clang failed:\n%s\n", txt)
os.Exit(-1)
}
lines := readAST(astPP)

View File

@ -350,7 +350,12 @@ func GoToC(name string, pnames []string, rtype *Type, ptypes []*Type) string {
if IsGoInterface(rtgt) {
rtgt = "*Id"
}
ret.WriteString("return (" + rtgt + ")(")
if rtgt == "BOOL" {
ret.WriteString("return (")
rtgt = "bool"
} else {
ret.WriteString("return (" + rtgt + ")(")
}
if rtype.IsPointer() {
ret.WriteString("unsafe.Pointer(")
}
@ -382,6 +387,9 @@ func GoToC(name string, pnames []string, rtype *Type, ptypes []*Type) string {
ret.WriteString(")")
}
}
if rt == "BOOL" {
ret.WriteString(" != 0")
}
return ret.String()
}

View File

@ -610,6 +610,9 @@ func (w *Wrapper) _processMethod(m *Method,fun bool) {
if types.IsGoInterface(grtype) {
grtype = "*Id"
}
if grtype == "BOOL" { // convert objective-c bools to Go bools
grtype = "bool"
}
if gname == grtype { // avoid name conflicts between methods and types
gname = "Get" + gname
}