Commit Graph

10 Commits

Author SHA1 Message Date
Elias Naur 6a96d4c7cf bind: make the default name prefix empty on ObjC
Since generated names now have their package names prefixed, the
extra prefix, "Go", is both confusing and counter-productive to
making the generated ObjC code look like any other native code.

Change the default to the empty prefix, while preserving support
for an explicit prefix if needed.

This is a backwards incompatible change; to keep the old behaviour,
specify "-prefix Go" to the gobind or gomobile command.

While we're here, fix the Ivy example for the recent change in
error returns.

Change-Id: I7fef4a92a18ddadee972ccf359652e3b31624f33
Reviewed-on: https://go-review.googlesource.com/34643
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-12-24 13:37:27 +00:00
Elias Naur 60feeb77f4 bind,cmd: support the empty ObjC prefix
Since the Go package name is already prefixed to generated ObjC
names, the empty extra prefix is useful. Support that by not reverting
to the default extra prefix, "Go", if -prefix "" is specified.

To avoid file name clashes with the Go header files, add ".objc" to
the ObjC-facing header names.

Change-Id: I559fe60d7474521617f23894af247c6019ff2a21
Reviewed-on: https://go-review.googlesource.com/33954
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-12-23 09:44:24 +00:00
Elias Naur 1c49d29d1c bind,cmd: accept ObjC wrapper types in bound packages
Accept ObjC API wrapper types as arguments and return values from
bound Go package functions and methods. Also, allow Go structs
to extend ObjC classes and implement ObjC protocols as well as override
and implement methods.

This is the third and final part of the implementation of the golang/go#17102
proposal.

Fixes golang/go#17102

Change-Id: I601d90fb6d22b8d6f8b7d5fe0130daa1a4dd4734
Reviewed-on: https://go-review.googlesource.com/29175
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-10-17 10:37:16 +00:00
Hana Kim d38f5ba53d bind: map Go's int type to Objective-C's long type
https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaTouch64BitGuide/Major64-BitChanges/Major64-BitChanges.html

Fixes golang/go#16182

Change-Id: I312749e8a7113bf9231eb3896f801e450f46a410
Reviewed-on: https://go-review.googlesource.com/24792
Reviewed-by: Elias Naur <elias.naur@gmail.com>
2016-07-07 16:20:08 +00:00
Elias Naur a3e0621280 mobile/bind: use objects to pass errors across the language barrier
Gobind uses strings for passing errors across the language barrier.
However, since Gobind doesn't have a concept of a nil string, it
can't separate an empty native string from a nil string.

In turn, that means that empty errors, exceptions or NSError * with
an empty description are treated as no error. With ObjC, empty errors
are replaced with a default string to workaround the issue, while
with Java empty errors are silently ignored.

Fix this by replacing strings with actual error objects, wrapping
the Go error, Java Throwable or ObjC NSError *, and letting the
existing bind machinery take care of passing the references across.

It's a large change for a small corner case, but I believe objects
are a better fit for exception that strings. Error objects also
naturally leads to future additions, for example accessing the
exception class name or chained exception.

Change-Id: Ie03b47cafcb231ad1e12a80195693fa7459c6265
Reviewed-on: https://go-review.googlesource.com/24100
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2016-06-23 18:55:48 +00:00
Elias Naur 976d0710d0 mobile/bind: merge iOS and Android Go test packages
Currently there is a Go test package for each platform, iOS and
Android. This CL merges them into a single, shared  package. Apart
from the reduced code duplication, the merger stops the tests
diverging further. Most importantly, one shared package clarifies
that the intent of gobind is that the same Go package can be
reused across platforms.

This CL only merges the obvious test duplicates. The rest have been
copied from the ObjC package into the Android test under different
names.

While we're here, demote the long string test to the basictypes
bind test; the test never had a runtime part.

Change-Id: I7838b16999968fae7b012016a5b5f6bb80f94023
Reviewed-on: https://go-review.googlesource.com/20300
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2016-03-07 16:10:51 +00:00
Hyang-Ah (Hana) Kim 60728759f9 bind: add const type support
Update golang/go#12475

Change-Id: I7fdc22462b5925c84ebbeb54517032c2fbd0545b
Reviewed-on: https://go-review.googlesource.com/15120
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-09-30 20:56:48 +00:00
Hyang-Ah (Hana) Kim 6fb2670129 bind/objc: Remove reference of seq.h from generated header file.
This allows gomobile bind to stop copying seq.h to the destination.

Change-Id: I4a23613fe0407500ad483ae9d8f6bb823d82f082
Reviewed-on: https://go-review.googlesource.com/12300
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-16 14:02:16 +00:00
Hyang-Ah (Hana) Kim a922dd97b1 bind/objc: remove '_' after Go<pkgname> prefix from names.
Before this change, func Hello() of mypkg package generated a function
GoMypkg_Hello to distinguish the prefix from the function name.
It seems the use of '_' is very rare in Objective-C though.
After this change, it generates GoMypkgHello.

Change-Id: Ic7aa2b667363a447a5ff3500262502d3137d6853
Reviewed-on: https://go-review.googlesource.com/11893
Reviewed-by: Damien Neil <dneil@google.com>
2015-07-07 03:29:17 +00:00
Hyang-Ah (Hana) Kim 8f4eb9eb49 bind: add objective-c code generator.
Translate error type to NSError.
Interface type is not supported yet.

Change-Id: I54abba2360cff41ef8ca08063b0120e7edd65a47
Reviewed-on: https://go-review.googlesource.com/10793
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2015-06-09 20:58:21 +00:00