├── .gitattributes ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── PATENTS ├── README.md ├── app ├── GoNativeActivity.java ├── android.c ├── android.go ├── app.go ├── app_test.go ├── darwin_desktop.go ├── darwin_desktop.m ├── darwin_ios.go ├── darwin_ios.m ├── doc.go ├── internal │ ├── apptest │ │ └── apptest.go │ ├── callfn │ │ ├── callfn.go │ │ ├── callfn_386.s │ │ ├── callfn_amd64.s │ │ ├── callfn_arm.s │ │ └── callfn_arm64.s │ └── testapp │ │ ├── AndroidManifest.xml │ │ └── testapp.go ├── shiny.go ├── x11.c └── x11.go ├── asset ├── asset.go ├── asset_android.go ├── asset_desktop.go ├── asset_ios.go └── doc.go ├── bind ├── bind.go ├── bind_test.go ├── gen.go ├── genclasses.go ├── gengo.go ├── genjava.go ├── genobjc.go ├── genobjcw.go ├── implicit.go ├── java │ ├── ClassesTest.java │ ├── CustomPkgTest.java │ ├── Seq.java │ ├── SeqBench.java │ ├── SeqTest.java │ ├── context_android.c │ ├── context_android.go │ ├── doc.go │ ├── seq_android.c.support │ ├── seq_android.go.support │ ├── seq_android.h │ └── seq_test.go ├── objc │ ├── SeqBench.m │ ├── SeqCustom.m │ ├── SeqTest.m │ ├── SeqWrappers.m │ ├── doc.go │ ├── ref.h │ ├── seq_darwin.go.support │ ├── seq_darwin.h │ ├── seq_darwin.m.support │ └── seq_test.go ├── printer.go ├── seq.go.support ├── seq │ ├── ref.go │ ├── seq.go │ ├── string.go │ └── string_test.go ├── testdata │ ├── basictypes.go │ ├── basictypes.go.golden │ ├── basictypes.java.c.golden │ ├── basictypes.java.golden │ ├── basictypes.java.h.golden │ ├── basictypes.objc.go.h.golden │ ├── basictypes.objc.h.golden │ ├── basictypes.objc.m.golden │ ├── benchmark │ │ └── benchmark.go │ ├── cgopkg │ │ └── cgopkg.go │ ├── classes.go │ ├── classes.go.golden │ ├── classes.java.c.golden │ ├── classes.java.golden │ ├── classes.java.h.golden │ ├── customprefix.go │ ├── customprefix.java.c.golden │ ├── customprefix.java.golden │ ├── customprefix.java.h.golden │ ├── customprefix.objc.go.h.golden │ ├── customprefix.objc.h.golden │ ├── customprefix.objc.m.golden │ ├── customprefixEX.objc.go.h.golden │ ├── customprefixEX.objc.h.golden │ ├── customprefixEX.objc.m.golden │ ├── doc.go │ ├── doc.go.golden │ ├── doc.java.c.golden │ ├── doc.java.golden │ ├── doc.java.h.golden │ ├── doc.objc.go.h.golden │ ├── doc.objc.h.golden │ ├── doc.objc.m.golden │ ├── ignore.go │ ├── ignore.go.golden │ ├── ignore.java.c.golden │ ├── ignore.java.golden │ ├── ignore.java.h.golden │ ├── ignore.objc.go.h.golden │ ├── ignore.objc.h.golden │ ├── ignore.objc.m.golden │ ├── interfaces.go │ ├── interfaces.go.golden │ ├── interfaces.java.c.golden │ ├── interfaces.java.golden │ ├── interfaces.java.h.golden │ ├── interfaces.objc.go.h.golden │ ├── interfaces.objc.h.golden │ ├── interfaces.objc.m.golden │ ├── issue10788.go │ ├── issue10788.go.golden │ ├── issue10788.java.c.golden │ ├── issue10788.java.golden │ ├── issue10788.java.h.golden │ ├── issue10788.objc.go.h.golden │ ├── issue10788.objc.h.golden │ ├── issue10788.objc.m.golden │ ├── issue12328.go │ ├── issue12328.go.golden │ ├── issue12328.java.c.golden │ ├── issue12328.java.golden │ ├── issue12328.java.h.golden │ ├── issue12328.objc.go.h.golden │ ├── issue12328.objc.h.golden │ ├── issue12328.objc.m.golden │ ├── issue12403.go │ ├── issue12403.go.golden │ ├── issue12403.java.c.golden │ ├── issue12403.java.golden │ ├── issue12403.java.h.golden │ ├── issue12403.objc.go.h.golden │ ├── issue12403.objc.h.golden │ ├── issue12403.objc.m.golden │ ├── issue29559.go │ ├── issue29559.go.golden │ ├── issue29559.java.c.golden │ ├── issue29559.java.golden │ ├── issue29559.java.h.golden │ ├── issue29559.objc.go.h.golden │ ├── issue29559.objc.h.golden │ ├── issue29559.objc.m.golden │ ├── java.go │ ├── java.go.golden │ ├── java.java.c.golden │ ├── java.java.golden │ ├── java.java.h.golden │ ├── keywords.go │ ├── keywords.go.golden │ ├── keywords.java.c.golden │ ├── keywords.java.golden │ ├── keywords.java.h.golden │ ├── keywords.objc.go.h.golden │ ├── keywords.objc.h.golden │ ├── keywords.objc.m.golden │ ├── objc.go │ ├── objc.go.golden │ ├── objcw.go │ ├── objcw.go.golden │ ├── structs.go │ ├── structs.go.golden │ ├── structs.java.c.golden │ ├── structs.java.golden │ ├── structs.java.h.golden │ ├── structs.objc.go.h.golden │ ├── structs.objc.h.golden │ ├── structs.objc.m.golden │ ├── testpkg │ │ ├── assets │ │ │ └── hello.txt │ │ ├── javapkg │ │ │ ├── classes.go │ │ │ └── java.go │ │ ├── objcpkg │ │ │ ├── classes.go │ │ │ └── objc.go │ │ ├── secondpkg │ │ │ └── secondpkg.go │ │ ├── simplepkg │ │ │ └── simplepkg.go │ │ ├── tagged.go │ │ ├── testpkg.go │ │ └── unboundpkg │ │ │ └── unboundpkg.go │ ├── try.go │ ├── try.go.golden │ ├── try.java.c.golden │ ├── try.java.golden │ ├── try.java.h.golden │ ├── try.objc.go.h.golden │ ├── try.objc.h.golden │ ├── try.objc.m.golden │ ├── underscores.go │ ├── underscores.go.golden │ ├── underscores.java.c.golden │ ├── underscores.java.golden │ ├── underscores.java.h.golden │ ├── underscores.objc.go.h.golden │ ├── underscores.objc.h.golden │ ├── underscores.objc.m.golden │ ├── universe.golden │ ├── universe.java.c.golden │ ├── universe.java.golden │ ├── universe.java.h.golden │ ├── universe.objc.go.h.golden │ ├── universe.objc.h.golden │ ├── universe.objc.m.golden │ ├── vars.go │ ├── vars.go.golden │ ├── vars.java.c.golden │ ├── vars.java.golden │ ├── vars.java.h.golden │ ├── vars.objc.go.h.golden │ ├── vars.objc.h.golden │ └── vars.objc.m.golden └── types.go ├── cmd ├── gobind │ ├── doc.go │ ├── gen.go │ ├── gobind_test.go │ ├── implicit.go │ └── main.go └── gomobile │ ├── bind.go │ ├── bind_androidapp.go │ ├── bind_iosapp.go │ ├── bind_test.go │ ├── build.go │ ├── build_androidapp.go │ ├── build_apple.go │ ├── build_darwin_test.go │ ├── build_test.go │ ├── cert.go │ ├── cert_test.go │ ├── clean.go │ ├── dex.go │ ├── doc.go │ ├── env.go │ ├── env_test.go │ ├── gendex.go │ ├── init.go │ ├── init_test.go │ ├── install.go │ ├── main.go │ ├── manifest.go │ ├── strings_flag.go │ ├── tools.go │ ├── version.go │ ├── writer.go │ └── writer_test.go ├── codereview.cfg ├── doc └── caution.png ├── event ├── key │ ├── code_string.go │ └── key.go ├── lifecycle │ └── lifecycle.go ├── mouse │ └── mouse.go ├── paint │ └── paint.go ├── size │ └── size.go └── touch │ └── touch.go ├── example ├── basic │ ├── main.go │ └── main_x.go ├── bind │ ├── android │ │ ├── README │ │ ├── app │ │ │ ├── build.gradle │ │ │ └── src │ │ │ │ └── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── java │ │ │ │ └── org │ │ │ │ │ └── golang │ │ │ │ │ └── example │ │ │ │ │ └── bind │ │ │ │ │ └── MainActivity.java │ │ │ │ └── res │ │ │ │ ├── layout │ │ │ │ └── activity_main.xml │ │ │ │ └── values │ │ │ │ └── dimens.xml │ │ ├── build.gradle │ │ └── settings.gradle │ ├── hello │ │ └── hello.go │ └── ios │ │ ├── README │ │ ├── bind.xcodeproj │ │ └── project.pbxproj │ │ └── bind │ │ ├── AppDelegate.h │ │ ├── AppDelegate.m │ │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── ViewController.h │ │ ├── ViewController.m │ │ └── main.m ├── flappy │ ├── assets │ │ ├── README │ │ └── sprite.png │ ├── game.go │ ├── main.go │ └── main_x.go ├── ivy │ ├── android │ │ ├── README.md │ │ ├── app │ │ │ ├── build.gradle │ │ │ ├── proguard-rules.pro │ │ │ └── src │ │ │ │ ├── androidTest │ │ │ │ └── java │ │ │ │ │ └── org │ │ │ │ │ └── golang │ │ │ │ │ └── ivy │ │ │ │ │ └── ApplicationTest.java │ │ │ │ └── main │ │ │ │ ├── AndroidManifest.xml │ │ │ │ ├── assets │ │ │ │ ├── aboutivy.html │ │ │ │ ├── demo.ivy │ │ │ │ └── tape.html │ │ │ │ ├── ic_launcher-web.png │ │ │ │ ├── java │ │ │ │ └── org │ │ │ │ │ └── golang │ │ │ │ │ └── ivy │ │ │ │ │ ├── AboutIvy.java │ │ │ │ │ ├── Help.java │ │ │ │ │ └── MainActivity.java │ │ │ │ └── res │ │ │ │ ├── drawable-hdpi │ │ │ │ ├── actionbar_solid.png │ │ │ │ └── ic_done_white_24dp.png │ │ │ │ ├── drawable-mdpi │ │ │ │ ├── actionbar_solid.png │ │ │ │ └── ic_done_white_24dp.png │ │ │ │ ├── drawable-xhdpi │ │ │ │ ├── actionbar_solid.png │ │ │ │ └── ic_done_white_24dp.png │ │ │ │ ├── drawable-xxhdpi │ │ │ │ ├── actionbar_solid.png │ │ │ │ └── ic_done_white_24dp.png │ │ │ │ ├── drawable │ │ │ │ ├── circle_shape.xml │ │ │ │ └── ivyabout.png │ │ │ │ ├── layout │ │ │ │ ├── activity_about.xml │ │ │ │ ├── activity_help.xml │ │ │ │ └── activity_main.xml │ │ │ │ ├── menu │ │ │ │ ├── menu_about.xml │ │ │ │ └── menu_main.xml │ │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ │ ├── values-w820dp │ │ │ │ ├── dimens.xml │ │ │ │ └── strings.xml │ │ │ │ └── values │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ ├── build.gradle │ │ └── settings.gradle │ ├── doc.go │ ├── go.mod │ ├── go.sum │ ├── ios │ │ ├── README.md │ │ ├── ivy.xcodeproj │ │ │ └── project.pbxproj │ │ └── ivy │ │ │ ├── AppDelegate.h │ │ │ ├── AppDelegate.m │ │ │ ├── Base.lproj │ │ │ └── Main.storyboard │ │ │ ├── DocsController.h │ │ │ ├── DocsController.m │ │ │ ├── Images.xcassets │ │ │ └── AppIcon.appiconset │ │ │ │ ├── Contents.json │ │ │ │ ├── icon-100.png │ │ │ │ ├── icon-1024.png │ │ │ │ ├── icon-120.png │ │ │ │ ├── icon-128.png │ │ │ │ ├── icon-152.png │ │ │ │ ├── icon-16.png │ │ │ │ ├── icon-167.png │ │ │ │ ├── icon-172.png │ │ │ │ ├── icon-180.png │ │ │ │ ├── icon-196.png │ │ │ │ ├── icon-20.png │ │ │ │ ├── icon-216.png │ │ │ │ ├── icon-256.png │ │ │ │ ├── icon-29.png │ │ │ │ ├── icon-32.png │ │ │ │ ├── icon-40.png │ │ │ │ ├── icon-48.png │ │ │ │ ├── icon-512.png │ │ │ │ ├── icon-55.png │ │ │ │ ├── icon-58.png │ │ │ │ ├── icon-60.png │ │ │ │ ├── icon-64.png │ │ │ │ ├── icon-76.png │ │ │ │ ├── icon-80.png │ │ │ │ ├── icon-87.png │ │ │ │ └── icon-88.png │ │ │ ├── Info.plist │ │ │ ├── IvyController.h │ │ │ ├── IvyController.m │ │ │ ├── Suggestion.h │ │ │ ├── Suggestion.m │ │ │ ├── en.lproj │ │ │ └── Main.strings │ │ │ ├── main.m │ │ │ └── tape.html │ └── tools.go └── network │ ├── AndroidManifest.xml │ ├── main.go │ └── main_x.go ├── exp ├── README ├── app │ └── debug │ │ └── fps.go ├── audio │ └── al │ │ ├── al.go │ │ ├── al_android.go │ │ ├── al_notandroid.go │ │ ├── alc.go │ │ ├── alc_android.go │ │ ├── alc_notandroid.go │ │ └── const.go ├── f32 │ ├── affine.go │ ├── affine_test.go │ ├── f32.go │ ├── f32_test.go │ ├── gen.go │ ├── mat3.go │ ├── mat4.go │ ├── table.go │ ├── vec3.go │ └── vec4.go ├── font │ ├── doc.go │ ├── font.go │ ├── font_android.go │ ├── font_darwin.go │ ├── font_linux.go │ └── font_test.go ├── gl │ └── glutil │ │ ├── context_darwin_desktop.go │ │ ├── context_x11.go │ │ ├── doc.go │ │ ├── glimage.go │ │ ├── glimage_test.go │ │ └── glutil.go ├── sensor │ ├── android.c │ ├── android.go │ ├── darwin_armx.go │ ├── darwin_armx.m │ ├── notmobile.go │ └── sensor.go └── sprite │ ├── clock │ ├── clock.go │ ├── tween.go │ └── tween_test.go │ ├── glsprite │ └── glsprite.go │ ├── portable │ ├── affine_test.go │ └── portable.go │ └── sprite.go ├── geom └── geom.go ├── gl ├── consts.go ├── dll_windows.go ├── doc.go ├── fn.go ├── gendebug.go ├── gl.go ├── gldebug.go ├── interface.go ├── types_debug.go ├── types_prod.go ├── work.c ├── work.go ├── work.h ├── work_other.go ├── work_windows.go ├── work_windows_386.s └── work_windows_amd64.s ├── go.mod ├── go.sum ├── internal ├── binres │ ├── arsc.go │ ├── binres.go │ ├── binres_string.go │ ├── binres_test.go │ ├── genarsc.go │ ├── node.go │ ├── pool.go │ ├── sdk.go │ ├── table.go │ └── testdata │ │ ├── bootstrap-res │ │ └── mipmap-xxxhdpi │ │ │ └── icon.png │ │ ├── bootstrap.arsc │ │ ├── bootstrap.bin │ │ ├── bootstrap.xml │ │ └── gen.sh ├── importers │ ├── ast.go │ ├── ast_test.go │ ├── java │ │ ├── java.go │ │ └── java_test.go │ └── objc │ │ ├── objc.go │ │ └── objc_test.go ├── mobileinit │ ├── ctx_android.go │ ├── mobileinit.go │ ├── mobileinit_android.go │ └── mobileinit_ios.go └── sdkpath │ └── sdkpath.go └── testdata ├── gophercolor.png ├── gopherswim.png ├── testpattern-window.png └── testpattern.png /.gitattributes: -------------------------------------------------------------------------------- 1 | # Treat all files in this repo as binary, with no git magic updating 2 | # line endings. Windows users contributing to Go will need to use a 3 | # modern version of git and editors capable of LF line endings. 4 | # 5 | # We'll prevent accidental CRLF line endings from entering the repo 6 | # via the git-review gofmt checks. 7 | # 8 | # See golang.org/issue/9281 9 | 10 | * -text 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Add no patterns to .gitignore except for files generated by the build. 2 | last-change 3 | *.apk 4 | *.app 5 | *.framework 6 | *.xcframework 7 | *.aar 8 | *.jar 9 | *.iml 10 | .idea 11 | .gradle 12 | *.properties 13 | .DS_Store 14 | example/ivy/**/build/ 15 | example/ivy/android/gradle/ 16 | 17 | # Xcode configuration files. 18 | *.xcworkspace 19 | xcuserdata 20 | *.entitlements 21 | 22 | # Android Studio build and IDE configuration files. 23 | example/bind/android/local.properties 24 | example/bind/android/gradlew* 25 | example/bind/android/gradle 26 | example/bind/android/build 27 | example/bind/android/app/build 28 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Go 2 | 3 | Go is an open source project. 4 | 5 | It is the work of hundreds of contributors. We appreciate your help! 6 | 7 | ## Filing issues 8 | 9 | When [filing an issue](https://golang.org/issue/new), make sure to answer these five questions: 10 | 11 | 1. What version of Go are you using (`go version`)? 12 | 2. What operating system and processor architecture are you using? 13 | 3. What did you do? 14 | 4. What did you expect to see? 15 | 5. What did you see instead? 16 | 17 | General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker. 18 | The gophers there will answer or ask you to file an issue if you've tripped over a bug. 19 | 20 | ## Contributing code 21 | 22 | Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html) 23 | before sending patches. 24 | 25 | Unless otherwise noted, the Go source files are distributed under 26 | the BSD-style license found in the LICENSE file. 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2009 The Go Authors. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google LLC nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Go support for Mobile devices 2 | 3 | [![Go Reference](https://pkg.go.dev/badge/golang.org/x/mobile.svg)](https://pkg.go.dev/golang.org/x/mobile) 4 | 5 | The Go mobile repository holds packages and build tools for using Go on mobile platforms. 6 | 7 | Package documentation as a starting point: 8 | 9 | - [Building all-Go apps](https://golang.org/x/mobile/app) 10 | - [Building libraries for SDK apps](https://golang.org/x/mobile/cmd/gobind) 11 | 12 | ![Caution image](doc/caution.png) 13 | 14 | The Go Mobile project is experimental. Use this at your own risk. 15 | While we are working hard to improve it, neither Google nor the Go 16 | team can provide end-user support. 17 | 18 | This is early work and installing the build system requires Go 1.5. 19 | Follow the instructions on 20 | [golang.org/wiki/Mobile](https://golang.org/wiki/Mobile) 21 | to install the gomobile command, build the 22 | [basic](https://golang.org/x/mobile/example/basic) 23 | and the [bind](https://golang.org/x/mobile/example/bind) example apps. 24 | 25 | -- 26 | 27 | Contributions to Go are appreciated. See https://go.dev/doc/contribute. 28 | 29 | The git repository is https://go.googlesource.com/mobile. 30 | 31 | * Bugs can be filed at the [Go issue tracker](https://go.dev/issue/new?title=x/mobile:+). 32 | * Feature requests should preliminary be discussed on 33 | [golang-nuts](https://groups.google.com/forum/#!forum/golang-nuts) 34 | mailing list. 35 | -------------------------------------------------------------------------------- /app/internal/apptest/apptest.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package apptest provides utilities for testing an app. 6 | // 7 | // It is extremely incomplete, hence it being internal. 8 | // For starters, it should support iOS. 9 | package apptest 10 | 11 | import ( 12 | "bufio" 13 | "bytes" 14 | "fmt" 15 | "net" 16 | ) 17 | 18 | // Port is the TCP port used to communicate with the test app. 19 | // 20 | // TODO(crawshaw): find a way to make this configurable. adb am extras? 21 | const Port = "12533" 22 | 23 | // Comm is a simple text-based communication protocol. 24 | // 25 | // Assumes all sides are friendly and cooperative and that the 26 | // communication is over at the first sign of trouble. 27 | type Comm struct { 28 | Conn net.Conn 29 | Fatalf func(format string, args ...interface{}) 30 | Printf func(format string, args ...interface{}) 31 | 32 | scanner *bufio.Scanner 33 | } 34 | 35 | func (c *Comm) Send(cmd string, args ...interface{}) { 36 | buf := new(bytes.Buffer) 37 | buf.WriteString(cmd) 38 | for _, arg := range args { 39 | buf.WriteRune(' ') 40 | fmt.Fprintf(buf, "%v", arg) 41 | } 42 | buf.WriteRune('\n') 43 | b := buf.Bytes() 44 | c.Printf("comm.send: %s\n", b) 45 | if _, err := c.Conn.Write(b); err != nil { 46 | c.Fatalf("failed to send %s: %v", b, err) 47 | } 48 | } 49 | 50 | func (c *Comm) Recv(cmd string, a ...interface{}) { 51 | if c.scanner == nil { 52 | c.scanner = bufio.NewScanner(c.Conn) 53 | } 54 | if !c.scanner.Scan() { 55 | c.Fatalf("failed to recv %q: %v", cmd, c.scanner.Err()) 56 | } 57 | text := c.scanner.Text() 58 | c.Printf("comm.recv: %s\n", text) 59 | var recvCmd string 60 | args := append([]interface{}{&recvCmd}, a...) 61 | if _, err := fmt.Sscan(text, args...); err != nil { 62 | c.Fatalf("cannot scan recv command %s: %q: %v", cmd, text, err) 63 | } 64 | if cmd != recvCmd { 65 | c.Fatalf("expecting recv %q, got %v", cmd, text) 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/internal/callfn/callfn.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build android && (arm || 386 || amd64 || arm64) 6 | 7 | // Package callfn provides an android entry point. 8 | // 9 | // It is a separate package from app because it contains Go assembly, 10 | // which does not compile in a package using cgo. 11 | package callfn 12 | 13 | // CallFn calls a zero-argument function by its program counter. 14 | // It is only intended for calling main.main. Using it for 15 | // anything else will not end well. 16 | func CallFn(fn uintptr) 17 | -------------------------------------------------------------------------------- /app/internal/callfn/callfn_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | #include "funcdata.h" 7 | 8 | TEXT ·CallFn(SB),$0-4 9 | MOVL fn+0(FP), AX 10 | CALL AX 11 | RET 12 | -------------------------------------------------------------------------------- /app/internal/callfn/callfn_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | #include "funcdata.h" 7 | 8 | TEXT ·CallFn(SB),$0-8 9 | MOVQ fn+0(FP), AX 10 | CALL AX 11 | RET 12 | -------------------------------------------------------------------------------- /app/internal/callfn/callfn_arm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | #include "funcdata.h" 7 | 8 | TEXT ·CallFn(SB),$0-4 9 | MOVW fn+0(FP), R0 10 | BL (R0) 11 | RET 12 | -------------------------------------------------------------------------------- /app/internal/callfn/callfn_arm64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | #include "funcdata.h" 7 | 8 | TEXT ·CallFn(SB),$0-8 9 | MOVD fn+0(FP), R0 10 | BL (R0) 11 | RET 12 | -------------------------------------------------------------------------------- /app/internal/testapp/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/shiny.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build windows 6 | 7 | package app 8 | 9 | import ( 10 | "log" 11 | 12 | "golang.org/x/exp/shiny/driver/gldriver" 13 | "golang.org/x/exp/shiny/screen" 14 | "golang.org/x/mobile/event/lifecycle" 15 | "golang.org/x/mobile/event/mouse" 16 | "golang.org/x/mobile/event/touch" 17 | "golang.org/x/mobile/gl" 18 | ) 19 | 20 | func main(f func(a App)) { 21 | gldriver.Main(func(s screen.Screen) { 22 | w, err := s.NewWindow(nil) 23 | if err != nil { 24 | log.Fatal(err) 25 | } 26 | defer w.Release() 27 | 28 | theApp.glctx = nil 29 | theApp.worker = nil // handled by shiny 30 | 31 | go func() { 32 | for range theApp.publish { 33 | res := w.Publish() 34 | theApp.publishResult <- PublishResult{ 35 | BackBufferPreserved: res.BackBufferPreserved, 36 | } 37 | } 38 | }() 39 | 40 | donec := make(chan struct{}) 41 | go func() { 42 | // close the donec channel in a defer statement 43 | // so that we could still be able to return even 44 | // if f panics. 45 | defer close(donec) 46 | 47 | f(theApp) 48 | }() 49 | 50 | for { 51 | select { 52 | case <-donec: 53 | return 54 | default: 55 | theApp.Send(convertEvent(w.NextEvent())) 56 | } 57 | } 58 | }) 59 | } 60 | 61 | func convertEvent(e interface{}) interface{} { 62 | switch e := e.(type) { 63 | case lifecycle.Event: 64 | if theApp.glctx == nil { 65 | theApp.glctx = e.DrawContext.(gl.Context) 66 | } 67 | case mouse.Event: 68 | te := touch.Event{ 69 | X: e.X, 70 | Y: e.Y, 71 | } 72 | switch e.Direction { 73 | case mouse.DirNone: 74 | te.Type = touch.TypeMove 75 | case mouse.DirPress: 76 | te.Type = touch.TypeBegin 77 | case mouse.DirRelease: 78 | te.Type = touch.TypeEnd 79 | } 80 | return te 81 | } 82 | return e 83 | } 84 | -------------------------------------------------------------------------------- /asset/asset.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build darwin || linux || windows 6 | 7 | package asset 8 | 9 | import "io" 10 | 11 | // Open opens a named asset. 12 | // 13 | // Errors are of type *os.PathError. 14 | // 15 | // This must not be called from init when used in android apps. 16 | func Open(name string) (File, error) { 17 | return openAsset(name) 18 | } 19 | 20 | // File is an open asset. 21 | type File interface { 22 | io.ReadSeeker 23 | io.Closer 24 | } 25 | -------------------------------------------------------------------------------- /asset/asset_desktop.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build (linux && !android) || (darwin && !ios) || windows 6 | 7 | package asset 8 | 9 | import ( 10 | "os" 11 | "path/filepath" 12 | ) 13 | 14 | func openAsset(name string) (File, error) { 15 | if !filepath.IsAbs(name) { 16 | name = filepath.Join("assets", name) 17 | } 18 | f, err := os.Open(name) 19 | if err != nil { 20 | return nil, err 21 | } 22 | return f, nil 23 | } 24 | -------------------------------------------------------------------------------- /asset/asset_ios.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package asset 6 | 7 | import ( 8 | "os" 9 | ) 10 | 11 | func openAsset(name string) (File, error) { 12 | return os.Open(name) 13 | } 14 | -------------------------------------------------------------------------------- /asset/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package asset provides access to application-bundled assets. 6 | // 7 | // On Android, assets are accessed via android.content.res.AssetManager. 8 | // These files are stored in the assets/ directory of the app. Any raw asset 9 | // can be accessed by its direct relative name. For example assets/img.png 10 | // can be opened with Open("img.png"). 11 | // 12 | // On iOS an asset is a resource stored in the application bundle. 13 | // Resources can be loaded using the same relative paths. 14 | // 15 | // For consistency when debugging on a desktop, assets are read from a 16 | // directory named assets under the current working directory. 17 | package asset 18 | -------------------------------------------------------------------------------- /bind/bind.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package bind implements a code generator for gobind. 6 | // 7 | // See the documentation on the gobind command for usage details 8 | // and the list of currently supported types. 9 | // (http://godoc.org/golang.org/x/mobile/cmd/gobind) 10 | package bind 11 | 12 | // TODO(crawshaw): slice support 13 | // TODO(crawshaw): channel support 14 | 15 | import ( 16 | "bytes" 17 | "go/format" 18 | "go/token" 19 | "go/types" 20 | "io" 21 | ) 22 | 23 | const gobindPreamble = "// Code generated by gobind. DO NOT EDIT.\n\n" 24 | 25 | type ( 26 | GeneratorConfig struct { 27 | Writer io.Writer 28 | Fset *token.FileSet 29 | Pkg *types.Package 30 | AllPkg []*types.Package 31 | } 32 | 33 | fileType int 34 | ) 35 | 36 | // GenGo generates a Go stub to support foreign language APIs. 37 | func GenGo(conf *GeneratorConfig) error { 38 | buf := new(bytes.Buffer) 39 | g := &goGen{ 40 | Generator: &Generator{ 41 | Printer: &Printer{Buf: buf, IndentEach: []byte("\t")}, 42 | Fset: conf.Fset, 43 | AllPkg: conf.AllPkg, 44 | Pkg: conf.Pkg, 45 | }, 46 | } 47 | g.Init() 48 | if err := g.gen(); err != nil { 49 | return err 50 | } 51 | src := buf.Bytes() 52 | srcf, err := format.Source(src) 53 | if err != nil { 54 | conf.Writer.Write(src) // for debugging 55 | return err 56 | } 57 | _, err = conf.Writer.Write(srcf) 58 | return err 59 | } 60 | -------------------------------------------------------------------------------- /bind/implicit.go: -------------------------------------------------------------------------------- 1 | // This file imports implicit dependencies required by generated code. 2 | 3 | //go:build mobile_implicit 4 | 5 | package bind 6 | 7 | import ( 8 | _ "golang.org/x/mobile/bind/seq" 9 | ) 10 | -------------------------------------------------------------------------------- /bind/java/CustomPkgTest.java: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package go; 6 | 7 | import android.test.InstrumentationTestCase; 8 | 9 | import org.golang.custompkg.testpkg.Testpkg; 10 | 11 | public class CustomPkgTest extends InstrumentationTestCase { 12 | public void testHi() { 13 | Testpkg.hi(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /bind/java/context_android.c: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include 6 | #include "seq_android.h" 7 | #include "_cgo_export.h" 8 | 9 | JNIEXPORT void JNICALL 10 | Java_go_Seq_setContext(JNIEnv* env, jclass clazz, jobject ctx) { 11 | JavaVM* vm; 12 | if ((*env)->GetJavaVM(env, &vm) != 0) { 13 | LOG_FATAL("failed to get JavaVM"); 14 | } 15 | setContext(vm, (*env)->NewGlobalRef(env, ctx)); 16 | } 17 | -------------------------------------------------------------------------------- /bind/java/context_android.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package java 6 | 7 | // #cgo LDFLAGS: -llog 8 | // 9 | //#include 10 | import "C" 11 | 12 | import ( 13 | "unsafe" 14 | 15 | "golang.org/x/mobile/internal/mobileinit" 16 | ) 17 | 18 | //export setContext 19 | func setContext(vm *C.JavaVM, ctx C.jobject) { 20 | mobileinit.SetCurrentContext(unsafe.Pointer(vm), uintptr(ctx)) 21 | } 22 | -------------------------------------------------------------------------------- /bind/java/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package java implements the Java language bindings. 6 | // 7 | // See the design document (http://golang.org/s/gobind). 8 | package java 9 | -------------------------------------------------------------------------------- /bind/objc/SeqCustom.m: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build ignore 6 | // +build ignore 7 | 8 | #import 9 | #import 10 | @import Testpkg; 11 | 12 | @interface tests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation tests 17 | 18 | - (void)testBasics { 19 | CustomTestpkgHi(); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /bind/objc/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package objc implements the Objective-C language bindings. 6 | package objc 7 | -------------------------------------------------------------------------------- /bind/objc/ref.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #ifndef __GO_REF_HDR__ 6 | #define __GO_REF_HDR__ 7 | 8 | #include 9 | 10 | // GoSeqRef is an object tagged with an integer for passing back and 11 | // forth across the language boundary. A GoSeqRef may represent either 12 | // an instance of a Go object, or an Objective-C object passed to Go. 13 | // The explicit allocation of a GoSeqRef is used to pin a Go object 14 | // when it is passed to Objective-C. The Go seq package maintains a 15 | // reference to the Go object in a map keyed by the refnum along with 16 | // a reference count. When the reference count reaches zero, the Go 17 | // seq package will clear the corresponding entry in the map. 18 | @interface GoSeqRef : NSObject { 19 | } 20 | @property(readonly) int32_t refnum; 21 | @property(strong) id obj; // NULL when representing a Go object. 22 | 23 | // new GoSeqRef object to proxy a Go object. The refnum must be 24 | // provided from Go side. 25 | - (instancetype)initWithRefnum:(int32_t)refnum obj:(id)obj; 26 | 27 | - (int32_t)incNum; 28 | 29 | @end 30 | 31 | @protocol goSeqRefInterface 32 | -(GoSeqRef*) _ref; 33 | @end 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /bind/printer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package bind 6 | 7 | import ( 8 | "bytes" 9 | "fmt" 10 | ) 11 | 12 | type Printer struct { 13 | Buf *bytes.Buffer 14 | IndentEach []byte 15 | indentText []byte 16 | needIndent bool 17 | } 18 | 19 | func (p *Printer) writeIndent() error { 20 | if !p.needIndent { 21 | return nil 22 | } 23 | p.needIndent = false 24 | _, err := p.Buf.Write(p.indentText) 25 | return err 26 | } 27 | 28 | func (p *Printer) Write(b []byte) (n int, err error) { 29 | wrote := 0 30 | for len(b) > 0 { 31 | if err := p.writeIndent(); err != nil { 32 | return wrote, err 33 | } 34 | i := bytes.IndexByte(b, '\n') 35 | if i < 0 { 36 | break 37 | } 38 | n, err = p.Buf.Write(b[0 : i+1]) 39 | wrote += n 40 | if err != nil { 41 | return wrote, err 42 | } 43 | b = b[i+1:] 44 | p.needIndent = true 45 | } 46 | if len(b) > 0 { 47 | n, err = p.Buf.Write(b) 48 | wrote += n 49 | } 50 | return wrote, err 51 | } 52 | 53 | func (p *Printer) Printf(format string, args ...interface{}) { 54 | if _, err := fmt.Fprintf(p, format, args...); err != nil { 55 | panic(fmt.Sprintf("printer: %v", err)) 56 | } 57 | } 58 | 59 | func (p *Printer) Indent() { 60 | p.indentText = append(p.indentText, p.IndentEach...) 61 | } 62 | 63 | func (p *Printer) Outdent() { 64 | if len(p.indentText) > len(p.IndentEach)-1 { 65 | p.indentText = p.indentText[len(p.IndentEach):] 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /bind/seq.go.support: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | // Go support functions for generated Go bindings. This file is 8 | // copied into the generated main package, and compiled along 9 | // with the bindings. 10 | 11 | // #cgo android CFLAGS: -D__GOBIND_ANDROID__ 12 | // #cgo darwin CFLAGS: -D__GOBIND_DARWIN__ 13 | // #include 14 | // #include "seq.h" 15 | import "C" 16 | 17 | import ( 18 | "fmt" 19 | "os" 20 | "os/signal" 21 | "syscall" 22 | 23 | _ "golang.org/x/mobile/bind/java" 24 | _seq "golang.org/x/mobile/bind/seq" 25 | ) 26 | 27 | func init() { 28 | _seq.FinalizeRef = func(ref *_seq.Ref) { 29 | refnum := ref.Bind_Num 30 | if refnum < 0 { 31 | panic(fmt.Sprintf("not a foreign ref: %d", refnum)) 32 | } 33 | C.go_seq_dec_ref(C.int32_t(refnum)) 34 | } 35 | _seq.IncForeignRef = func(refnum int32) { 36 | if refnum < 0 { 37 | panic(fmt.Sprintf("not a foreign ref: %d", refnum)) 38 | } 39 | C.go_seq_inc_ref(C.int32_t(refnum)) 40 | } 41 | // Workaround for issue #17393. 42 | signal.Notify(make(chan os.Signal), syscall.SIGPIPE) 43 | } 44 | 45 | // IncGoRef is called by foreign code to pin a Go object while its refnum is crossing 46 | // the language barrier 47 | //export IncGoRef 48 | func IncGoRef(refnum C.int32_t) { 49 | _seq.Inc(int32(refnum)) 50 | } 51 | 52 | func main() {} 53 | -------------------------------------------------------------------------------- /bind/seq/seq.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package seq implements the machine-dependent seq serialization format. 6 | // 7 | // Implementations of Transact and FinalizeRef are provided by a 8 | // specific foreign language binding package, e.g. go.mobile/bind/java. 9 | // 10 | // Designed only for use by the code generated by gobind. Don't try to 11 | // use this directly. 12 | package seq 13 | 14 | import _ "golang.org/x/mobile/internal/mobileinit" 15 | 16 | // FinalizeRef is the finalizer used on foreign objects. 17 | var FinalizeRef func(ref *Ref) 18 | 19 | // IncRef increments the foreign reference count for ref while it is in transit. 20 | // The count is decremented after the ref is received and translated on the foreign side. 21 | var IncForeignRef func(refnum int32) 22 | -------------------------------------------------------------------------------- /bind/seq/string.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package seq 6 | 7 | import "unicode/utf16" 8 | 9 | // Based heavily on package unicode/utf16 from the Go standard library. 10 | 11 | const ( 12 | replacementChar = '\uFFFD' // Unicode replacement character 13 | maxRune = '\U0010FFFF' // Maximum valid Unicode code point. 14 | ) 15 | 16 | const ( 17 | // 0xd800-0xdc00 encodes the high 10 bits of a pair. 18 | // 0xdc00-0xe000 encodes the low 10 bits of a pair. 19 | // the value is those 20 bits plus 0x10000. 20 | surr1 = 0xd800 21 | surr2 = 0xdc00 22 | surr3 = 0xe000 23 | 24 | surrSelf = 0x10000 25 | ) 26 | 27 | // UTF16Encode utf16 encodes s into chars. It returns the resulting 28 | // length in units of uint16. It is assumed that the chars slice 29 | // has enough room for the encoded string. 30 | func UTF16Encode(s string, chars []uint16) int { 31 | n := 0 32 | for _, v := range s { 33 | switch { 34 | case v < 0, surr1 <= v && v < surr3, v > maxRune: 35 | v = replacementChar 36 | fallthrough 37 | case v < surrSelf: 38 | chars[n] = uint16(v) 39 | n += 1 40 | default: 41 | // surrogate pair, two uint16 values 42 | r1, r2 := utf16.EncodeRune(v) 43 | chars[n] = uint16(r1) 44 | chars[n+1] = uint16(r2) 45 | n += 2 46 | } 47 | } 48 | return n 49 | } 50 | -------------------------------------------------------------------------------- /bind/seq/string_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package seq 6 | 7 | import ( 8 | "testing" 9 | "unicode/utf16" 10 | ) 11 | 12 | var strData = []string{ 13 | "abcxyz09{}", 14 | "Hello, 世界", 15 | string([]rune{0xffff, 0x10000, 0x10001, 0x12345, 0x10ffff}), 16 | } 17 | 18 | func TestString(t *testing.T) { 19 | for _, test := range strData { 20 | chars := make([]uint16, 4*len(test)) 21 | nchars := UTF16Encode(test, chars) 22 | chars = chars[:nchars] 23 | got := string(utf16.Decode(chars)) 24 | if got != test { 25 | t.Errorf("UTF16: got %q, want %q", got, test) 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /bind/testdata/basictypes.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package basictypes 6 | 7 | const ( 8 | AString = "a string" 9 | AnInt = 7 10 | AnInt2 = 1<<63 - 1 11 | AFloat = 0.2015 12 | ARune = rune(32) 13 | ABool = true 14 | ALongString = "LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString" 15 | ) 16 | 17 | func Ints(x int8, y int16, z int32, t int64, u int) {} 18 | 19 | func Error() error { return nil } 20 | 21 | func ErrorPair() (int, error) { return 0, nil } 22 | 23 | func ByteArrays(x []byte) []byte { return nil } 24 | 25 | func Bool(bool) bool { return true } 26 | -------------------------------------------------------------------------------- /bind/testdata/basictypes.go.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // Package main is an autogenerated binder stub for package basictypes. 4 | // 5 | // autogenerated by gobind -lang=go basictypes 6 | package main 7 | 8 | /* 9 | #include 10 | #include 11 | #include "seq.h" 12 | #include "basictypes.h" 13 | 14 | */ 15 | import "C" 16 | 17 | import ( 18 | "basictypes" 19 | _seq "golang.org/x/mobile/bind/seq" 20 | ) 21 | 22 | // suppress the error if seq ends up unused 23 | var _ = _seq.FromRefNum 24 | 25 | //export proxybasictypes__Bool 26 | func proxybasictypes__Bool(param_p0 C.char) C.char { 27 | _param_p0 := param_p0 != 0 28 | res_0 := basictypes.Bool(_param_p0) 29 | var _res_0 C.char = 0 30 | if res_0 { 31 | _res_0 = 1 32 | } 33 | return _res_0 34 | } 35 | 36 | //export proxybasictypes__ByteArrays 37 | func proxybasictypes__ByteArrays(param_x C.nbyteslice) C.nbyteslice { 38 | _param_x := toSlice(param_x, false) 39 | res_0 := basictypes.ByteArrays(_param_x) 40 | _res_0 := fromSlice(res_0, true) 41 | return _res_0 42 | } 43 | 44 | //export proxybasictypes__Error 45 | func proxybasictypes__Error() C.int32_t { 46 | res_0 := basictypes.Error() 47 | var _res_0 C.int32_t = _seq.NullRefNum 48 | if res_0 != nil { 49 | _res_0 = C.int32_t(_seq.ToRefNum(res_0)) 50 | } 51 | return _res_0 52 | } 53 | 54 | //export proxybasictypes__ErrorPair 55 | func proxybasictypes__ErrorPair() (C.nint, C.int32_t) { 56 | res_0, res_1 := basictypes.ErrorPair() 57 | _res_0 := C.nint(res_0) 58 | var _res_1 C.int32_t = _seq.NullRefNum 59 | if res_1 != nil { 60 | _res_1 = C.int32_t(_seq.ToRefNum(res_1)) 61 | } 62 | return _res_0, _res_1 63 | } 64 | 65 | //export proxybasictypes__Ints 66 | func proxybasictypes__Ints(param_x C.int8_t, param_y C.int16_t, param_z C.int32_t, param_t C.int64_t, param_u C.nint) { 67 | _param_x := int8(param_x) 68 | _param_y := int16(param_y) 69 | _param_z := int32(param_z) 70 | _param_t := int64(param_t) 71 | _param_u := int(param_u) 72 | basictypes.Ints(_param_x, _param_y, _param_z, _param_t, _param_u) 73 | } 74 | -------------------------------------------------------------------------------- /bind/testdata/basictypes.java.c.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI functions for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java basictypes 6 | 7 | #include 8 | #include 9 | #include "seq.h" 10 | #include "_cgo_export.h" 11 | #include "basictypes.h" 12 | 13 | 14 | JNIEXPORT void JNICALL 15 | Java_basictypes_Basictypes__1init(JNIEnv *env, jclass _unused) { 16 | jclass clazz; 17 | } 18 | 19 | JNIEXPORT jboolean JNICALL 20 | Java_basictypes_Basictypes_bool(JNIEnv* env, jclass _clazz, jboolean p0) { 21 | char _p0 = (char)p0; 22 | char r0 = proxybasictypes__Bool(_p0); 23 | jboolean _r0 = r0 ? JNI_TRUE : JNI_FALSE; 24 | return _r0; 25 | } 26 | 27 | JNIEXPORT jbyteArray JNICALL 28 | Java_basictypes_Basictypes_byteArrays(JNIEnv* env, jclass _clazz, jbyteArray x) { 29 | nbyteslice _x = go_seq_from_java_bytearray(env, x, 0); 30 | nbyteslice r0 = proxybasictypes__ByteArrays(_x); 31 | go_seq_release_byte_array(env, x, _x.ptr); 32 | jbyteArray _r0 = go_seq_to_java_bytearray(env, r0, 1); 33 | return _r0; 34 | } 35 | 36 | JNIEXPORT void JNICALL 37 | Java_basictypes_Basictypes_error(JNIEnv* env, jclass _clazz) { 38 | int32_t r0 = proxybasictypes__Error(); 39 | jobject _r0 = go_seq_from_refnum(env, r0, proxy_class__error, proxy_class__error_cons); 40 | go_seq_maybe_throw_exception(env, _r0); 41 | } 42 | 43 | JNIEXPORT jlong JNICALL 44 | Java_basictypes_Basictypes_errorPair(JNIEnv* env, jclass _clazz) { 45 | struct proxybasictypes__ErrorPair_return res = proxybasictypes__ErrorPair(); 46 | jlong _r0 = (jlong)res.r0; 47 | jobject _r1 = go_seq_from_refnum(env, res.r1, proxy_class__error, proxy_class__error_cons); 48 | go_seq_maybe_throw_exception(env, _r1); 49 | return _r0; 50 | } 51 | 52 | JNIEXPORT void JNICALL 53 | Java_basictypes_Basictypes_ints(JNIEnv* env, jclass _clazz, jbyte x, jshort y, jint z, jlong t, jlong u) { 54 | int8_t _x = (int8_t)x; 55 | int16_t _y = (int16_t)y; 56 | int32_t _z = (int32_t)z; 57 | int64_t _t = (int64_t)t; 58 | nint _u = (nint)u; 59 | proxybasictypes__Ints(_x, _y, _z, _t, _u); 60 | } 61 | 62 | -------------------------------------------------------------------------------- /bind/testdata/basictypes.java.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // Java class basictypes.Basictypes is a proxy for talking to a Go program. 4 | // 5 | // autogenerated by gobind -lang=java basictypes 6 | package basictypes; 7 | 8 | import go.Seq; 9 | 10 | public abstract class Basictypes { 11 | static { 12 | Seq.touch(); // for loading the native library 13 | _init(); 14 | } 15 | 16 | private Basictypes() {} // uninstantiable 17 | 18 | // touch is called from other bound packages to initialize this package 19 | public static void touch() {} 20 | 21 | private static native void _init(); 22 | 23 | 24 | public static final boolean ABool = true; 25 | public static final double AFloat = 0.2015; 26 | public static final String ALongString = "LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString,LongString"; 27 | public static final int ARune = 32; 28 | public static final String AString = "a string"; 29 | public static final long AnInt = 7L; 30 | public static final long AnInt2 = 9223372036854775807L; 31 | 32 | public static native boolean bool(boolean p0); 33 | public static native byte[] byteArrays(byte[] x); 34 | public static native void error() throws Exception; 35 | public static native long errorPair() throws Exception; 36 | public static native void ints(byte x, short y, int z, long t, long u); 37 | } 38 | -------------------------------------------------------------------------------- /bind/testdata/basictypes.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI function headers for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java basictypes 6 | 7 | #ifndef __Basictypes_H__ 8 | #define __Basictypes_H__ 9 | 10 | #include 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /bind/testdata/basictypes.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to basictypes Go package. 2 | // gobind -lang=objc basictypes 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO_basictypes_H__ 7 | #define __GO_basictypes_H__ 8 | 9 | #include 10 | #include 11 | #endif 12 | -------------------------------------------------------------------------------- /bind/testdata/basictypes.objc.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to basictypes Go package. 2 | // gobind -lang=objc basictypes 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __Basictypes_H__ 7 | #define __Basictypes_H__ 8 | 9 | @import Foundation; 10 | #include "ref.h" 11 | #include "Universe.objc.h" 12 | 13 | 14 | FOUNDATION_EXPORT const BOOL BasictypesABool; 15 | FOUNDATION_EXPORT const double BasictypesAFloat; 16 | FOUNDATION_EXPORT NSString* _Nonnull const BasictypesALongString; 17 | FOUNDATION_EXPORT const int32_t BasictypesARune; 18 | FOUNDATION_EXPORT NSString* _Nonnull const BasictypesAString; 19 | FOUNDATION_EXPORT const int64_t BasictypesAnInt; 20 | FOUNDATION_EXPORT const int64_t BasictypesAnInt2; 21 | 22 | FOUNDATION_EXPORT BOOL BasictypesBool(BOOL p0); 23 | 24 | FOUNDATION_EXPORT NSData* _Nullable BasictypesByteArrays(NSData* _Nullable x); 25 | 26 | FOUNDATION_EXPORT BOOL BasictypesError(NSError* _Nullable* _Nullable error); 27 | 28 | FOUNDATION_EXPORT BOOL BasictypesErrorPair(long* _Nullable ret0_, NSError* _Nullable* _Nullable error); 29 | 30 | FOUNDATION_EXPORT void BasictypesInts(int8_t x, int16_t y, int32_t z, int64_t t, long u); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /bind/testdata/cgopkg/cgopkg.go: -------------------------------------------------------------------------------- 1 | package cgopkg 2 | 3 | import "C" 4 | 5 | import ( 6 | _ "golang.org/x/mobile/gl" 7 | ) 8 | 9 | func Dummy() {} 10 | -------------------------------------------------------------------------------- /bind/testdata/classes.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package java 6 | 7 | import ( 8 | gopkg "Java/java" 9 | "Java/java/io" 10 | "Java/java/lang" 11 | "Java/java/lang/System" 12 | "Java/java/util/Spliterators" 13 | "Java/java/util/concurrent" 14 | ) 15 | 16 | type Runnable struct { 17 | lang.Runnable 18 | } 19 | 20 | func (r *Runnable) Run(this gopkg.Runnable) { 21 | } 22 | 23 | type InputStream struct { 24 | io.InputStream 25 | } 26 | 27 | func (_ *InputStream) Read() (int32, error) { 28 | return 0, nil 29 | } 30 | 31 | func NewInputStream() *InputStream { 32 | return new(InputStream) 33 | } 34 | 35 | type Future struct { 36 | concurrent.Future 37 | } 38 | 39 | func (_ *Future) Get() (lang.Object, error) { 40 | return nil, nil 41 | } 42 | 43 | // Use a trailing underscore to override multiple overloaded methods. 44 | func (_ *Future) Get_(_ int64, _ concurrent.TimeUnit) (lang.Object, error) { 45 | return nil, nil 46 | } 47 | 48 | type Object struct { 49 | lang.Object 50 | } 51 | 52 | func innerClassTypes() { 53 | // java.util.Spliterators.iterator use inner class types 54 | // for the return value as well as parameters. 55 | Spliterators.Iterator(nil) 56 | } 57 | 58 | func returnType() { 59 | // Implicit types (java.io.Console) should be wrapped. 60 | cons := System.Console() 61 | cons.Flush() 62 | } 63 | -------------------------------------------------------------------------------- /bind/testdata/customprefix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Data for -pkgpath and -prefix options. 6 | 7 | package customprefix 8 | 9 | func F() { 10 | } 11 | -------------------------------------------------------------------------------- /bind/testdata/customprefix.java.c.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI functions for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java -javapkg=com.example customprefix 6 | 7 | #include 8 | #include 9 | #include "seq.h" 10 | #include "_cgo_export.h" 11 | #include "customprefix.h" 12 | 13 | 14 | JNIEXPORT void JNICALL 15 | Java_com_example_customprefix_Customprefix__1init(JNIEnv *env, jclass _unused) { 16 | jclass clazz; 17 | } 18 | 19 | JNIEXPORT void JNICALL 20 | Java_com_example_customprefix_Customprefix_f(JNIEnv* env, jclass _clazz) { 21 | proxycustomprefix__F(); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /bind/testdata/customprefix.java.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // Java class com.example.customprefix.Customprefix is a proxy for talking to a Go program. 4 | // 5 | // autogenerated by gobind -lang=java -javapkg=com.example customprefix 6 | package com.example.customprefix; 7 | 8 | import go.Seq; 9 | 10 | public abstract class Customprefix { 11 | static { 12 | Seq.touch(); // for loading the native library 13 | _init(); 14 | } 15 | 16 | private Customprefix() {} // uninstantiable 17 | 18 | // touch is called from other bound packages to initialize this package 19 | public static void touch() {} 20 | 21 | private static native void _init(); 22 | 23 | 24 | 25 | public static native void f(); 26 | } 27 | -------------------------------------------------------------------------------- /bind/testdata/customprefix.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI function headers for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java -javapkg=com.example customprefix 6 | 7 | #ifndef __Customprefix_H__ 8 | #define __Customprefix_H__ 9 | 10 | #include 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /bind/testdata/customprefix.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to customprefix Go package. 2 | // gobind -lang=objc customprefix 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO_customprefix_H__ 7 | #define __GO_customprefix_H__ 8 | 9 | #include 10 | #include 11 | #endif 12 | -------------------------------------------------------------------------------- /bind/testdata/customprefix.objc.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to customprefix Go package. 2 | // gobind -lang=objc customprefix 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __Customprefix_H__ 7 | #define __Customprefix_H__ 8 | 9 | @import Foundation; 10 | #include "ref.h" 11 | #include "Universe.objc.h" 12 | 13 | 14 | FOUNDATION_EXPORT void CustomprefixF(void); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /bind/testdata/customprefix.objc.m.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to customprefix Go package. 2 | // gobind -lang=objc customprefix 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #include 7 | #include "seq.h" 8 | #include "_cgo_export.h" 9 | #include "Customprefix.objc.h" 10 | 11 | 12 | void CustomprefixF(void) { 13 | proxycustomprefix__F(); 14 | } 15 | 16 | __attribute__((constructor)) static void init() { 17 | init_seq(); 18 | } 19 | -------------------------------------------------------------------------------- /bind/testdata/customprefixEX.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to customprefix Go package. 2 | // gobind -lang=objc -prefix="EX" customprefix 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO_customprefix_H__ 7 | #define __GO_customprefix_H__ 8 | 9 | #include 10 | #include 11 | #endif 12 | -------------------------------------------------------------------------------- /bind/testdata/customprefixEX.objc.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to customprefix Go package. 2 | // gobind -lang=objc -prefix="EX" customprefix 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __EXCustomprefix_H__ 7 | #define __EXCustomprefix_H__ 8 | 9 | @import Foundation; 10 | #include "ref.h" 11 | #include "Universe.objc.h" 12 | 13 | 14 | FOUNDATION_EXPORT void EXCustomprefixF(void); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /bind/testdata/customprefixEX.objc.m.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to customprefix Go package. 2 | // gobind -lang=objc -prefix="EX" customprefix 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #include 7 | #include "seq.h" 8 | #include "_cgo_export.h" 9 | #include "EXCustomprefix.objc.h" 10 | 11 | 12 | void EXCustomprefixF(void) { 13 | proxycustomprefix__F(); 14 | } 15 | 16 | __attribute__((constructor)) static void init() { 17 | init_seq(); 18 | } 19 | -------------------------------------------------------------------------------- /bind/testdata/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // package doc tests that Go documentation is transferred 6 | // to the generated code. 7 | package doc 8 | 9 | // F is a function. 10 | func F() {} 11 | 12 | // C is a constant. 13 | const C = true 14 | 15 | // V is a var. 16 | var V string 17 | 18 | // A group of vars. 19 | var ( 20 | // A specific var. 21 | Specific string 22 | NoDocVar float64 23 | ) 24 | 25 | // Before is a method. 26 | func (_ *S) Before() {} 27 | 28 | // S is a struct. 29 | type S struct { 30 | // SF is a field. 31 | SF string 32 | // blank (unexported) field. 33 | _ string 34 | // Anonymous field. 35 | *S2 36 | // Multiple fields. 37 | F1, F2 string 38 | } 39 | 40 | // After is another method. 41 | func (_ *S) After() {} 42 | 43 | // A generic comment with . 44 | type ( 45 | // S2 is a struct. 46 | S2 struct{} 47 | NoDoc struct{} 48 | ) 49 | 50 | // NewS is a constructor. 51 | func NewS() *S { 52 | return nil 53 | } 54 | 55 | // I is an interface. 56 | type I interface { 57 | // IM is a method. 58 | IM() 59 | } 60 | -------------------------------------------------------------------------------- /bind/testdata/doc.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI function headers for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java doc 6 | 7 | #ifndef __Doc_H__ 8 | #define __Doc_H__ 9 | 10 | #include 11 | 12 | extern jclass proxy_class_doc_I; 13 | extern jmethodID proxy_class_doc_I_cons; 14 | 15 | void cproxydoc_I_IM(int32_t refnum); 16 | 17 | extern jclass proxy_class_doc_NoDoc; 18 | extern jmethodID proxy_class_doc_NoDoc_cons; 19 | extern jclass proxy_class_doc_S; 20 | extern jmethodID proxy_class_doc_S_cons; 21 | extern jclass proxy_class_doc_S2; 22 | extern jmethodID proxy_class_doc_S2_cons; 23 | #endif 24 | -------------------------------------------------------------------------------- /bind/testdata/doc.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to doc Go package. 2 | // gobind -lang=objc doc 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO_doc_H__ 7 | #define __GO_doc_H__ 8 | 9 | #include 10 | #include 11 | void cproxydoc_I_IM(int32_t refnum); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /bind/testdata/ignore.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // package ignore tests that exported, but otherwise 6 | // unsupported functions, variables, fields and methods 7 | // are ignored by the generators 8 | package ignore 9 | 10 | var Var interface{} 11 | 12 | type ( 13 | NamedString string 14 | ) 15 | 16 | const NamedConst NamedString = "foo" 17 | 18 | var V interface{} 19 | 20 | func Argument(_ interface{}) { 21 | } 22 | 23 | func Result() interface{} { 24 | return nil 25 | } 26 | 27 | type S struct { 28 | F interface{} 29 | } 30 | 31 | type ( 32 | F func() 33 | ) 34 | 35 | func (_ *S) Argument(_ interface{}) { 36 | } 37 | 38 | func (_ *S) Result() interface{} { 39 | return nil 40 | } 41 | 42 | type I interface { 43 | Argument(_ interface{}) 44 | Result() interface{} 45 | } 46 | 47 | var ( 48 | Uint uint 49 | Uint32 uint32 50 | Uint64 uint64 51 | C64 complex64 = 0 52 | C128 complex128 = 0 53 | ) 54 | 55 | const ( 56 | Cuint uint = 0 57 | Cuint32 uint32 = 0 58 | Cuint64 uint64 = 0 59 | ) 60 | -------------------------------------------------------------------------------- /bind/testdata/ignore.go.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // Package main is an autogenerated binder stub for package ignore. 4 | // 5 | // autogenerated by gobind -lang=go ignore 6 | package main 7 | 8 | /* 9 | #include 10 | #include 11 | #include "seq.h" 12 | #include "ignore.h" 13 | 14 | */ 15 | import "C" 16 | 17 | import ( 18 | _seq "golang.org/x/mobile/bind/seq" 19 | "ignore" 20 | ) 21 | 22 | // suppress the error if seq ends up unused 23 | var _ = _seq.FromRefNum 24 | 25 | // skipped field S.F with unsupported type: interface{} 26 | 27 | // skipped method S.Argument with unsupported parameter or return types 28 | 29 | // skipped method S.Result with unsupported parameter or return types 30 | 31 | //export new_ignore_S 32 | func new_ignore_S() C.int32_t { 33 | return C.int32_t(_seq.ToRefNum(new(ignore.S))) 34 | } 35 | 36 | // skipped method I.Argument with unsupported parameter or return types 37 | 38 | // skipped method I.Result with unsupported parameter or return types 39 | 40 | type proxyignore_I _seq.Ref 41 | 42 | func (p *proxyignore_I) Bind_proxy_refnum__() int32 { 43 | return (*_seq.Ref)(p).Bind_IncNum() 44 | } 45 | 46 | // skipped method I.Argument with unsupported parameter or result types 47 | // skipped method I.Result with unsupported parameter or result types 48 | // skipped variable C128 with unsupported type complex128 49 | 50 | // skipped variable C64 with unsupported type complex64 51 | 52 | // skipped variable Uint with unsupported type uint 53 | 54 | // skipped variable Uint32 with unsupported type uint32 55 | 56 | // skipped variable Uint64 with unsupported type uint64 57 | 58 | // skipped variable V with unsupported type interface{} 59 | 60 | // skipped variable Var with unsupported type interface{} 61 | 62 | // skipped function Argument with unsupported parameter or result types 63 | // skipped function Result with unsupported parameter or result types 64 | -------------------------------------------------------------------------------- /bind/testdata/ignore.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI function headers for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java ignore 6 | 7 | #ifndef __Ignore_H__ 8 | #define __Ignore_H__ 9 | 10 | #include 11 | 12 | extern jclass proxy_class_ignore_I; 13 | extern jmethodID proxy_class_ignore_I_cons; 14 | 15 | // skipped method I.Argument with unsupported parameter or return types 16 | 17 | // skipped method I.Result with unsupported parameter or return types 18 | 19 | extern jclass proxy_class_ignore_S; 20 | extern jmethodID proxy_class_ignore_S_cons; 21 | #endif 22 | -------------------------------------------------------------------------------- /bind/testdata/ignore.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to ignore Go package. 2 | // gobind -lang=objc ignore 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO_ignore_H__ 7 | #define __GO_ignore_H__ 8 | 9 | #include 10 | #include 11 | // skipped method I.Argument with unsupported parameter or return types 12 | 13 | // skipped method I.Result with unsupported parameter or return types 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /bind/testdata/interfaces.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package interfaces 6 | 7 | type I interface { 8 | Rand() int32 9 | } 10 | 11 | type SameI interface { 12 | Rand() int32 13 | } 14 | 15 | type LargerI interface { 16 | Rand() int32 17 | AnotherFunc() 18 | } 19 | 20 | func Add3(r I) int32 { 21 | return r.Rand() + r.Rand() + r.Rand() 22 | } 23 | 24 | // chosen by fair dice roll. 25 | // guaranteed to be random. 26 | type seven struct{} 27 | 28 | func (seven) Rand() int32 { return 7 } 29 | 30 | func Seven() I { return seven{} } 31 | 32 | type WithParam interface { 33 | HasParam(p bool) 34 | } 35 | 36 | type Error interface { 37 | Err() error 38 | } 39 | 40 | func CallErr(e Error) error { 41 | return e.Err() 42 | } 43 | 44 | // not implementable 45 | type I1 interface { 46 | J() 47 | H() *seven // not bound 48 | } 49 | 50 | // not implementable 51 | type I2 interface { 52 | f() 53 | G() 54 | } 55 | 56 | // implementable 57 | // (the implementor has to find a source of I1s) 58 | type I3 interface { 59 | F() I1 60 | } 61 | 62 | // not bound 63 | func F() seven { return seven{} } 64 | func G(u seven) {} 65 | 66 | // Interfaces is an interface with the same name as its package. 67 | type Interfaces interface { 68 | SomeMethod() 69 | } 70 | -------------------------------------------------------------------------------- /bind/testdata/interfaces.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI function headers for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java interfaces 6 | 7 | #ifndef __Interfaces_H__ 8 | #define __Interfaces_H__ 9 | 10 | #include 11 | 12 | extern jclass proxy_class_interfaces_Error; 13 | extern jmethodID proxy_class_interfaces_Error_cons; 14 | 15 | int32_t cproxyinterfaces_Error_Err(int32_t refnum); 16 | 17 | extern jclass proxy_class_interfaces_I; 18 | extern jmethodID proxy_class_interfaces_I_cons; 19 | 20 | int32_t cproxyinterfaces_I_Rand(int32_t refnum); 21 | 22 | extern jclass proxy_class_interfaces_I1; 23 | extern jmethodID proxy_class_interfaces_I1_cons; 24 | 25 | void cproxyinterfaces_I1_J(int32_t refnum); 26 | 27 | extern jclass proxy_class_interfaces_I2; 28 | extern jmethodID proxy_class_interfaces_I2_cons; 29 | 30 | void cproxyinterfaces_I2_G(int32_t refnum); 31 | 32 | extern jclass proxy_class_interfaces_I3; 33 | extern jmethodID proxy_class_interfaces_I3_cons; 34 | 35 | int32_t cproxyinterfaces_I3_F(int32_t refnum); 36 | 37 | extern jclass proxy_class_interfaces_Interfaces; 38 | extern jmethodID proxy_class_interfaces_Interfaces_cons; 39 | 40 | void cproxyinterfaces_Interfaces_SomeMethod(int32_t refnum); 41 | 42 | extern jclass proxy_class_interfaces_LargerI; 43 | extern jmethodID proxy_class_interfaces_LargerI_cons; 44 | 45 | void cproxyinterfaces_LargerI_AnotherFunc(int32_t refnum); 46 | 47 | int32_t cproxyinterfaces_LargerI_Rand(int32_t refnum); 48 | 49 | extern jclass proxy_class_interfaces_SameI; 50 | extern jmethodID proxy_class_interfaces_SameI_cons; 51 | 52 | int32_t cproxyinterfaces_SameI_Rand(int32_t refnum); 53 | 54 | extern jclass proxy_class_interfaces_WithParam; 55 | extern jmethodID proxy_class_interfaces_WithParam_cons; 56 | 57 | void cproxyinterfaces_WithParam_HasParam(int32_t refnum, char p0); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /bind/testdata/interfaces.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to interfaces Go package. 2 | // gobind -lang=objc interfaces 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO_interfaces_H__ 7 | #define __GO_interfaces_H__ 8 | 9 | #include 10 | #include 11 | int32_t cproxyinterfaces_Error_Err(int32_t refnum); 12 | 13 | int32_t cproxyinterfaces_I_Rand(int32_t refnum); 14 | 15 | int32_t cproxyinterfaces_I3_F(int32_t refnum); 16 | 17 | void cproxyinterfaces_Interfaces_SomeMethod(int32_t refnum); 18 | 19 | void cproxyinterfaces_LargerI_AnotherFunc(int32_t refnum); 20 | 21 | int32_t cproxyinterfaces_LargerI_Rand(int32_t refnum); 22 | 23 | int32_t cproxyinterfaces_SameI_Rand(int32_t refnum); 24 | 25 | void cproxyinterfaces_WithParam_HasParam(int32_t refnum, char p0); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /bind/testdata/issue10788.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package issue10788 6 | 7 | type TestStruct struct { 8 | Value string 9 | } 10 | 11 | type TestInterface interface { 12 | DoSomeWork(s *TestStruct) 13 | MultipleUnnamedParams(_ int, p0 string, 日本 int64) 14 | } 15 | -------------------------------------------------------------------------------- /bind/testdata/issue10788.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI function headers for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java issue10788 6 | 7 | #ifndef __Issue10788_H__ 8 | #define __Issue10788_H__ 9 | 10 | #include 11 | 12 | extern jclass proxy_class_issue10788_TestInterface; 13 | extern jmethodID proxy_class_issue10788_TestInterface_cons; 14 | 15 | void cproxyissue10788_TestInterface_DoSomeWork(int32_t refnum, int32_t s); 16 | 17 | void cproxyissue10788_TestInterface_MultipleUnnamedParams(int32_t refnum, nint p0, nstring p1, int64_t p2); 18 | 19 | extern jclass proxy_class_issue10788_TestStruct; 20 | extern jmethodID proxy_class_issue10788_TestStruct_cons; 21 | #endif 22 | -------------------------------------------------------------------------------- /bind/testdata/issue10788.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to issue10788 Go package. 2 | // gobind -lang=objc issue10788 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO_issue10788_H__ 7 | #define __GO_issue10788_H__ 8 | 9 | #include 10 | #include 11 | void cproxyissue10788_TestInterface_DoSomeWork(int32_t refnum, int32_t s); 12 | 13 | void cproxyissue10788_TestInterface_MultipleUnnamedParams(int32_t refnum, nint p0, nstring p1, int64_t 日本); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /bind/testdata/issue10788.objc.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to issue10788 Go package. 2 | // gobind -lang=objc issue10788 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __Issue10788_H__ 7 | #define __Issue10788_H__ 8 | 9 | @import Foundation; 10 | #include "ref.h" 11 | #include "Universe.objc.h" 12 | 13 | 14 | @class Issue10788TestStruct; 15 | @protocol Issue10788TestInterface; 16 | @class Issue10788TestInterface; 17 | 18 | @protocol Issue10788TestInterface 19 | - (void)doSomeWork:(Issue10788TestStruct* _Nullable)s; 20 | - (void)multipleUnnamedParams:(long)p0 p1:(NSString* _Nullable)p1 日本:(int64_t)日本; 21 | @end 22 | 23 | @interface Issue10788TestStruct : NSObject { 24 | } 25 | @property(strong, readonly) _Nonnull id _ref; 26 | 27 | - (nonnull instancetype)initWithRef:(_Nonnull id)ref; 28 | - (nonnull instancetype)init; 29 | @property (nonatomic) NSString* _Nonnull value; 30 | @end 31 | 32 | @class Issue10788TestInterface; 33 | 34 | @interface Issue10788TestInterface : NSObject { 35 | } 36 | @property(strong, readonly) _Nonnull id _ref; 37 | 38 | - (nonnull instancetype)initWithRef:(_Nonnull id)ref; 39 | - (void)doSomeWork:(Issue10788TestStruct* _Nullable)s; 40 | - (void)multipleUnnamedParams:(long)p0 p1:(NSString* _Nullable)p1 日本:(int64_t)日本; 41 | @end 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /bind/testdata/issue12328.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package issue12328 6 | 7 | type T struct { 8 | Err error 9 | } 10 | -------------------------------------------------------------------------------- /bind/testdata/issue12328.go.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // Package main is an autogenerated binder stub for package issue12328. 4 | // 5 | // autogenerated by gobind -lang=go issue12328 6 | package main 7 | 8 | /* 9 | #include 10 | #include 11 | #include "seq.h" 12 | #include "issue12328.h" 13 | 14 | */ 15 | import "C" 16 | 17 | import ( 18 | _seq "golang.org/x/mobile/bind/seq" 19 | "issue12328" 20 | ) 21 | 22 | // suppress the error if seq ends up unused 23 | var _ = _seq.FromRefNum 24 | 25 | //export proxyissue12328_T_Err_Set 26 | func proxyissue12328_T_Err_Set(refnum C.int32_t, v C.int32_t) { 27 | ref := _seq.FromRefNum(int32(refnum)) 28 | var _v error 29 | _v_ref := _seq.FromRefNum(int32(v)) 30 | if _v_ref != nil { 31 | if v < 0 { // go object 32 | _v = _v_ref.Get().(error) 33 | } else { // foreign object 34 | _v = (*proxy_error)(_v_ref) 35 | } 36 | } 37 | ref.Get().(*issue12328.T).Err = _v 38 | } 39 | 40 | //export proxyissue12328_T_Err_Get 41 | func proxyissue12328_T_Err_Get(refnum C.int32_t) C.int32_t { 42 | ref := _seq.FromRefNum(int32(refnum)) 43 | v := ref.Get().(*issue12328.T).Err 44 | var _v C.int32_t = _seq.NullRefNum 45 | if v != nil { 46 | _v = C.int32_t(_seq.ToRefNum(v)) 47 | } 48 | return _v 49 | } 50 | 51 | //export new_issue12328_T 52 | func new_issue12328_T() C.int32_t { 53 | return C.int32_t(_seq.ToRefNum(new(issue12328.T))) 54 | } 55 | -------------------------------------------------------------------------------- /bind/testdata/issue12328.java.c.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI functions for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java issue12328 6 | 7 | #include 8 | #include 9 | #include "seq.h" 10 | #include "_cgo_export.h" 11 | #include "issue12328.h" 12 | 13 | jclass proxy_class_issue12328_T; 14 | jmethodID proxy_class_issue12328_T_cons; 15 | 16 | JNIEXPORT void JNICALL 17 | Java_issue12328_Issue12328__1init(JNIEnv *env, jclass _unused) { 18 | jclass clazz; 19 | clazz = (*env)->FindClass(env, "issue12328/T"); 20 | proxy_class_issue12328_T = (*env)->NewGlobalRef(env, clazz); 21 | proxy_class_issue12328_T_cons = (*env)->GetMethodID(env, clazz, "", "(I)V"); 22 | } 23 | 24 | JNIEXPORT jint JNICALL 25 | Java_issue12328_T__1_1New(JNIEnv *env, jclass clazz) { 26 | return new_issue12328_T(); 27 | } 28 | 29 | JNIEXPORT void JNICALL 30 | Java_issue12328_T_setErr(JNIEnv *env, jobject this, jobject v) { 31 | int32_t o = go_seq_to_refnum_go(env, this); 32 | int32_t _v = go_seq_to_refnum(env, v); 33 | proxyissue12328_T_Err_Set(o, _v); 34 | } 35 | 36 | JNIEXPORT jobject JNICALL 37 | Java_issue12328_T_getErr(JNIEnv *env, jobject this) { 38 | int32_t o = go_seq_to_refnum_go(env, this); 39 | int32_t r0 = proxyissue12328_T_Err_Get(o); 40 | jobject _r0 = go_seq_from_refnum(env, r0, proxy_class__error, proxy_class__error_cons); 41 | return _r0; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /bind/testdata/issue12328.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI function headers for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java issue12328 6 | 7 | #ifndef __Issue12328_H__ 8 | #define __Issue12328_H__ 9 | 10 | #include 11 | 12 | extern jclass proxy_class_issue12328_T; 13 | extern jmethodID proxy_class_issue12328_T_cons; 14 | #endif 15 | -------------------------------------------------------------------------------- /bind/testdata/issue12328.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to issue12328 Go package. 2 | // gobind -lang=objc issue12328 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO_issue12328_H__ 7 | #define __GO_issue12328_H__ 8 | 9 | #include 10 | #include 11 | #endif 12 | -------------------------------------------------------------------------------- /bind/testdata/issue12328.objc.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to issue12328 Go package. 2 | // gobind -lang=objc issue12328 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __Issue12328_H__ 7 | #define __Issue12328_H__ 8 | 9 | @import Foundation; 10 | #include "ref.h" 11 | #include "Universe.objc.h" 12 | 13 | 14 | @class Issue12328T; 15 | 16 | @interface Issue12328T : NSObject { 17 | } 18 | @property(strong, readonly) _Nonnull id _ref; 19 | 20 | - (nonnull instancetype)initWithRef:(_Nonnull id)ref; 21 | - (nonnull instancetype)init; 22 | @property (nonatomic) NSError* _Nullable err; 23 | @end 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /bind/testdata/issue12328.objc.m.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to issue12328 Go package. 2 | // gobind -lang=objc issue12328 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #include 7 | #include "seq.h" 8 | #include "_cgo_export.h" 9 | #include "Issue12328.objc.h" 10 | 11 | 12 | @implementation Issue12328T { 13 | } 14 | 15 | - (nonnull instancetype)initWithRef:(_Nonnull id)ref { 16 | self = [super init]; 17 | if (self) { __ref = ref; } 18 | return self; 19 | } 20 | 21 | - (nonnull instancetype)init { 22 | self = [super init]; 23 | if (self) { 24 | __ref = go_seq_from_refnum(new_issue12328_T()); 25 | } 26 | return self; 27 | } 28 | 29 | - (NSError* _Nullable)err { 30 | int32_t refnum = go_seq_go_to_refnum(self._ref); 31 | int32_t r0 = proxyissue12328_T_Err_Get(refnum); 32 | Universeerror* _r0 = nil; 33 | GoSeqRef* _r0_ref = go_seq_from_refnum(r0); 34 | if (_r0_ref != NULL) { 35 | _r0 = _r0_ref.obj; 36 | if (_r0 == nil) { 37 | _r0 = [[Universeerror alloc] initWithRef:_r0_ref]; 38 | } 39 | } 40 | return _r0; 41 | } 42 | 43 | - (void)setErr:(NSError* _Nullable)v { 44 | int32_t refnum = go_seq_go_to_refnum(self._ref); 45 | int32_t _v; 46 | if ([v conformsToProtocol:@protocol(goSeqRefInterface)]) { 47 | id v_proxy = (id)(v); 48 | _v = go_seq_go_to_refnum(v_proxy._ref); 49 | } else { 50 | _v = go_seq_to_refnum(v); 51 | } 52 | proxyissue12328_T_Err_Set(refnum, _v); 53 | } 54 | 55 | @end 56 | 57 | 58 | 59 | __attribute__((constructor)) static void init() { 60 | init_seq(); 61 | } 62 | -------------------------------------------------------------------------------- /bind/testdata/issue12403.go: -------------------------------------------------------------------------------- 1 | package issue12403 2 | 3 | type Parsable interface { 4 | FromJSON(jstr string) string 5 | ToJSON() (string, error) 6 | } 7 | -------------------------------------------------------------------------------- /bind/testdata/issue12403.java.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // Java class issue12403.Parsable is a proxy for talking to a Go program. 4 | // 5 | // autogenerated by gobind -lang=java issue12403 6 | package issue12403; 7 | 8 | import go.Seq; 9 | 10 | public interface Parsable { 11 | public String fromJSON(String jstr); 12 | public String toJSON() throws Exception; 13 | 14 | } 15 | 16 | // Code generated by gobind. DO NOT EDIT. 17 | 18 | // Java class issue12403.Issue12403 is a proxy for talking to a Go program. 19 | // 20 | // autogenerated by gobind -lang=java issue12403 21 | package issue12403; 22 | 23 | import go.Seq; 24 | 25 | public abstract class Issue12403 { 26 | static { 27 | Seq.touch(); // for loading the native library 28 | _init(); 29 | } 30 | 31 | private Issue12403() {} // uninstantiable 32 | 33 | // touch is called from other bound packages to initialize this package 34 | public static void touch() {} 35 | 36 | private static native void _init(); 37 | 38 | private static final class proxyParsable implements Seq.Proxy, Parsable { 39 | private final int refnum; 40 | 41 | @Override public final int incRefnum() { 42 | Seq.incGoRef(refnum, this); 43 | return refnum; 44 | } 45 | 46 | proxyParsable(int refnum) { this.refnum = refnum; Seq.trackGoRef(refnum, this); } 47 | 48 | public native String fromJSON(String jstr); 49 | public native String toJSON() throws Exception; 50 | } 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /bind/testdata/issue12403.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI function headers for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java issue12403 6 | 7 | #ifndef __Issue12403_H__ 8 | #define __Issue12403_H__ 9 | 10 | #include 11 | 12 | extern jclass proxy_class_issue12403_Parsable; 13 | extern jmethodID proxy_class_issue12403_Parsable_cons; 14 | 15 | nstring cproxyissue12403_Parsable_FromJSON(int32_t refnum, nstring jstr); 16 | 17 | typedef struct cproxyissue12403_Parsable_ToJSON_return { 18 | nstring r0; 19 | int32_t r1; 20 | } cproxyissue12403_Parsable_ToJSON_return; 21 | struct cproxyissue12403_Parsable_ToJSON_return cproxyissue12403_Parsable_ToJSON(int32_t refnum); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /bind/testdata/issue12403.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to issue12403 Go package. 2 | // gobind -lang=objc issue12403 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO_issue12403_H__ 7 | #define __GO_issue12403_H__ 8 | 9 | #include 10 | #include 11 | nstring cproxyissue12403_Parsable_FromJSON(int32_t refnum, nstring jstr); 12 | 13 | typedef struct cproxyissue12403_Parsable_ToJSON_return { 14 | nstring r0; 15 | int32_t r1; 16 | } cproxyissue12403_Parsable_ToJSON_return; 17 | struct cproxyissue12403_Parsable_ToJSON_return cproxyissue12403_Parsable_ToJSON(int32_t refnum); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /bind/testdata/issue12403.objc.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to issue12403 Go package. 2 | // gobind -lang=objc issue12403 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __Issue12403_H__ 7 | #define __Issue12403_H__ 8 | 9 | @import Foundation; 10 | #include "ref.h" 11 | #include "Universe.objc.h" 12 | 13 | 14 | @protocol Issue12403Parsable; 15 | @class Issue12403Parsable; 16 | 17 | @protocol Issue12403Parsable 18 | - (NSString* _Nonnull)fromJSON:(NSString* _Nullable)jstr; 19 | - (NSString* _Nonnull)toJSON:(NSError* _Nullable* _Nullable)error; 20 | @end 21 | 22 | @class Issue12403Parsable; 23 | 24 | @interface Issue12403Parsable : NSObject { 25 | } 26 | @property(strong, readonly) _Nonnull id _ref; 27 | 28 | - (nonnull instancetype)initWithRef:(_Nonnull id)ref; 29 | - (NSString* _Nonnull)fromJSON:(NSString* _Nullable)jstr; 30 | - (NSString* _Nonnull)toJSON:(NSError* _Nullable* _Nullable)error; 31 | @end 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /bind/testdata/issue29559.go: -------------------------------------------------------------------------------- 1 | package issue29559 2 | 3 | type AString = string 4 | 5 | func TakesAString(s AString) {} 6 | -------------------------------------------------------------------------------- /bind/testdata/issue29559.go.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // Package main is an autogenerated binder stub for package issue29559. 4 | // 5 | // autogenerated by gobind -lang=go issue29559 6 | package main 7 | 8 | /* 9 | #include 10 | #include 11 | #include "seq.h" 12 | #include "issue29559.h" 13 | 14 | */ 15 | import "C" 16 | 17 | import ( 18 | _seq "golang.org/x/mobile/bind/seq" 19 | "issue29559" 20 | ) 21 | 22 | // suppress the error if seq ends up unused 23 | var _ = _seq.FromRefNum 24 | 25 | //export proxyissue29559__TakesAString 26 | func proxyissue29559__TakesAString(param_s C.nstring) { 27 | _param_s := decodeString(param_s) 28 | issue29559.TakesAString(_param_s) 29 | } 30 | -------------------------------------------------------------------------------- /bind/testdata/issue29559.java.c.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI functions for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java issue29559 6 | 7 | #include 8 | #include 9 | #include "seq.h" 10 | #include "_cgo_export.h" 11 | #include "issue29559.h" 12 | 13 | 14 | JNIEXPORT void JNICALL 15 | Java_issue29559_Issue29559__1init(JNIEnv *env, jclass _unused) { 16 | jclass clazz; 17 | } 18 | 19 | JNIEXPORT void JNICALL 20 | Java_issue29559_Issue29559_takesAString(JNIEnv* env, jclass _clazz, jstring s) { 21 | nstring _s = go_seq_from_java_string(env, s); 22 | proxyissue29559__TakesAString(_s); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /bind/testdata/issue29559.java.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // Java class issue29559.Issue29559 is a proxy for talking to a Go program. 4 | // 5 | // autogenerated by gobind -lang=java issue29559 6 | package issue29559; 7 | 8 | import go.Seq; 9 | 10 | public abstract class Issue29559 { 11 | static { 12 | Seq.touch(); // for loading the native library 13 | _init(); 14 | } 15 | 16 | private Issue29559() {} // uninstantiable 17 | 18 | // touch is called from other bound packages to initialize this package 19 | public static void touch() {} 20 | 21 | private static native void _init(); 22 | 23 | 24 | 25 | public static native void takesAString(String s); 26 | } 27 | -------------------------------------------------------------------------------- /bind/testdata/issue29559.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI function headers for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java issue29559 6 | 7 | #ifndef __Issue29559_H__ 8 | #define __Issue29559_H__ 9 | 10 | #include 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /bind/testdata/issue29559.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to issue29559 Go package. 2 | // gobind -lang=objc issue29559 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO_issue29559_H__ 7 | #define __GO_issue29559_H__ 8 | 9 | #include 10 | #include 11 | #endif 12 | -------------------------------------------------------------------------------- /bind/testdata/issue29559.objc.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to issue29559 Go package. 2 | // gobind -lang=objc issue29559 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __Issue29559_H__ 7 | #define __Issue29559_H__ 8 | 9 | @import Foundation; 10 | #include "ref.h" 11 | #include "Universe.objc.h" 12 | 13 | 14 | FOUNDATION_EXPORT void Issue29559TakesAString(NSString* _Nullable s); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /bind/testdata/issue29559.objc.m.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to issue29559 Go package. 2 | // gobind -lang=objc issue29559 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #include 7 | #include "seq.h" 8 | #include "_cgo_export.h" 9 | #include "Issue29559.objc.h" 10 | 11 | 12 | void Issue29559TakesAString(NSString* _Nullable s) { 13 | nstring _s = go_seq_from_objc_string(s); 14 | proxyissue29559__TakesAString(_s); 15 | } 16 | 17 | __attribute__((constructor)) static void init() { 18 | init_seq(); 19 | } 20 | -------------------------------------------------------------------------------- /bind/testdata/java.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package java 6 | 7 | import ( 8 | "Java/java/lang" 9 | ) 10 | 11 | type ( 12 | F lang.Float 13 | L lang.Long 14 | O lang.Object 15 | R lang.Runnable 16 | ) 17 | -------------------------------------------------------------------------------- /bind/testdata/java.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | 4 | #include 5 | #include "seq.h" 6 | 7 | extern void init_proxies(); 8 | 9 | typedef struct ret_jint { 10 | jint res; 11 | jint exc; 12 | } ret_jint; 13 | typedef struct ret_jboolean { 14 | jboolean res; 15 | jint exc; 16 | } ret_jboolean; 17 | typedef struct ret_jshort { 18 | jshort res; 19 | jint exc; 20 | } ret_jshort; 21 | typedef struct ret_jchar { 22 | jchar res; 23 | jint exc; 24 | } ret_jchar; 25 | typedef struct ret_jbyte { 26 | jbyte res; 27 | jint exc; 28 | } ret_jbyte; 29 | typedef struct ret_jlong { 30 | jlong res; 31 | jint exc; 32 | } ret_jlong; 33 | typedef struct ret_jfloat { 34 | jfloat res; 35 | jint exc; 36 | } ret_jfloat; 37 | typedef struct ret_jdouble { 38 | jdouble res; 39 | jint exc; 40 | } ret_jdouble; 41 | typedef struct ret_nstring { 42 | nstring res; 43 | jint exc; 44 | } ret_nstring; 45 | typedef struct ret_nbyteslice { 46 | nbyteslice res; 47 | jint exc; 48 | } ret_nbyteslice; 49 | 50 | extern ret_nstring cproxy_java_lang_Float_toString(jint this); 51 | extern ret_nstring cproxy_java_lang_Long_toString(jint this); 52 | extern ret_nstring cproxy_java_lang_Object_toString(jint this); 53 | // Code generated by gobind. DO NOT EDIT. 54 | 55 | // JNI function headers for the Go <=> Java bridge. 56 | // 57 | // autogenerated by gobind -lang=java java 58 | 59 | #ifndef __Java_H__ 60 | #define __Java_H__ 61 | 62 | #include 63 | 64 | extern jclass proxy_class_java_F; 65 | extern jmethodID proxy_class_java_F_cons; 66 | 67 | nstring cproxyjava_F_ToString(int32_t refnum); 68 | 69 | extern jclass proxy_class_java_L; 70 | extern jmethodID proxy_class_java_L_cons; 71 | 72 | nstring cproxyjava_L_ToString(int32_t refnum); 73 | 74 | extern jclass proxy_class_java_O; 75 | extern jmethodID proxy_class_java_O_cons; 76 | 77 | nstring cproxyjava_O_ToString(int32_t refnum); 78 | 79 | extern jclass proxy_class_java_R; 80 | extern jmethodID proxy_class_java_R_cons; 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /bind/testdata/keywords.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package keywords 6 | 7 | type KeywordCaller interface { 8 | Abstract() 9 | Assert() 10 | Boolean() 11 | Break() 12 | Byte() 13 | Case() 14 | Catch() 15 | Char() 16 | Class() 17 | Const() 18 | Continue() 19 | Default() 20 | Do() 21 | Double() 22 | Else() 23 | Enum() 24 | Extends() 25 | Final() 26 | Finally() 27 | Float() 28 | For() 29 | Goto() 30 | If() 31 | Implements() 32 | Import() 33 | Instanceof() 34 | Int() 35 | Interface() 36 | Long() 37 | Native() 38 | New() 39 | Package() 40 | Private() 41 | Protected() 42 | Public() 43 | Return() 44 | Short() 45 | Static() 46 | Strictfp() 47 | Super() 48 | Switch() 49 | Synchronized() 50 | This() 51 | Throw() 52 | Throws() 53 | Transient() 54 | Try() 55 | Void() 56 | Volatile() 57 | While() 58 | False() 59 | Null() 60 | True() 61 | Bool() 62 | Nil() 63 | } 64 | 65 | func Const(id string) {} 66 | func Static(strictfp string) {} 67 | -------------------------------------------------------------------------------- /bind/testdata/objc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package objc 6 | 7 | import ( 8 | "ObjC/Foundation" 9 | ) 10 | 11 | type ( 12 | S Foundation.NSString 13 | D Foundation.NSDate 14 | O Foundation.NSObjectC 15 | ) 16 | -------------------------------------------------------------------------------- /bind/testdata/objc.go.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | package ObjC 4 | 5 | // Used to silence this package not used errors 6 | const Dummy = 0 7 | 8 | type Foundation_NSString interface { 9 | } 10 | 11 | type Foundation_NSDate interface { 12 | } 13 | 14 | type Foundation_NSObjectC interface { 15 | } 16 | // Code generated by gobind. DO NOT EDIT. 17 | 18 | package main 19 | 20 | // #include "interfaces.h" 21 | import "C" 22 | 23 | import "ObjC" 24 | import _seq "golang.org/x/mobile/bind/seq" 25 | 26 | type proxy interface{ Bind_proxy_refnum__() int32 } 27 | 28 | // Suppress unused package error 29 | 30 | var _ = _seq.FromRefNum 31 | 32 | const _ = ObjC.Dummy 33 | 34 | func init() { 35 | } 36 | 37 | type proxy_class_NSString _seq.Ref 38 | 39 | func (p *proxy_class_NSString) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } 40 | 41 | func init() { 42 | } 43 | 44 | type proxy_class_NSDate _seq.Ref 45 | 46 | func (p *proxy_class_NSDate) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } 47 | 48 | func init() { 49 | } 50 | 51 | type proxy_class_NSObjectC _seq.Ref 52 | 53 | func (p *proxy_class_NSObjectC) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } 54 | // Code generated by gobind. DO NOT EDIT. 55 | 56 | // Package main is an autogenerated binder stub for package objc. 57 | // 58 | // autogenerated by gobind -lang=go objc 59 | package main 60 | 61 | /* 62 | #include 63 | #include 64 | #include "seq.h" 65 | #include "objc.h" 66 | 67 | */ 68 | import "C" 69 | 70 | import ( 71 | _seq "golang.org/x/mobile/bind/seq" 72 | ) 73 | 74 | // suppress the error if seq ends up unused 75 | var _ = _seq.FromRefNum 76 | 77 | type proxyobjc_D _seq.Ref 78 | 79 | func (p *proxyobjc_D) Bind_proxy_refnum__() int32 { 80 | return (*_seq.Ref)(p).Bind_IncNum() 81 | } 82 | 83 | type proxyobjc_O _seq.Ref 84 | 85 | func (p *proxyobjc_O) Bind_proxy_refnum__() int32 { 86 | return (*_seq.Ref)(p).Bind_IncNum() 87 | } 88 | 89 | type proxyobjc_S _seq.Ref 90 | 91 | func (p *proxyobjc_S) Bind_proxy_refnum__() int32 { 92 | return (*_seq.Ref)(p).Bind_IncNum() 93 | } 94 | -------------------------------------------------------------------------------- /bind/testdata/objcw.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package objc 6 | 7 | import ( 8 | "ObjC/Foundation" 9 | "ObjC/Foundation/NSMutableString" 10 | "ObjC/NetworkExtension/NEPacket" 11 | "ObjC/UIKit" 12 | ) 13 | 14 | type GoNSDate struct { 15 | Foundation.NSDate 16 | this Foundation.NSDate 17 | } 18 | 19 | func (d *GoNSDate) Hash(this Foundation.NSDate) int { 20 | return 0 21 | } 22 | 23 | type GoNSObject struct { 24 | C Foundation.NSObjectC // The class 25 | P Foundation.NSObjectP // The protocol 26 | } 27 | 28 | func (o *GoNSObject) Description(this Foundation.NSObjectC) string { 29 | return "" 30 | } 31 | 32 | func DupNSDate(date Foundation.NSDate) Foundation.NSDate { 33 | return date 34 | } 35 | 36 | type GoUIResponder struct { 37 | UIKit.UIResponder 38 | } 39 | 40 | func (r *GoUIResponder) PressesBegan(_ Foundation.NSSet, _ UIKit.UIPressesEvent) { 41 | } 42 | 43 | const NSUTF8StringEncoding = 8 44 | 45 | func CreateReadNSMutableString() { 46 | myData := []byte{'A', 'B'} 47 | // Test byte slices. Use NSMutableString because NSString is 48 | // represented as Go strings in bindings. 49 | // Pass slice from Go to native. 50 | mString := NSMutableString.NewWithData(myData, uint(NSUTF8StringEncoding)) 51 | // Pass slice from native to Go. 52 | _ = mString.DataUsingEncoding(uint(NSUTF8StringEncoding)) 53 | } 54 | 55 | // From 56 | const PF_INET = 2 57 | 58 | func CallUcharFunction() { 59 | _ = NEPacket.NewWithData(nil, uint8(PF_INET)) 60 | } 61 | -------------------------------------------------------------------------------- /bind/testdata/structs.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package structs 6 | 7 | type S struct { 8 | X, Y float64 9 | unexported bool 10 | } 11 | 12 | func (s *S) Sum() float64 { 13 | return s.X + s.Y 14 | } 15 | 16 | func (s *S) Identity() (*S, error) { 17 | return s, nil 18 | } 19 | 20 | func Identity(s *S) *S { 21 | return s 22 | } 23 | 24 | func IdentityWithError(s *S) (*S, error) { 25 | return s, nil 26 | } 27 | 28 | type ( 29 | S2 struct{} 30 | I interface { 31 | M() 32 | } 33 | ) 34 | 35 | func (s *S2) M() { 36 | } 37 | 38 | func (_ *S2) String() string { 39 | return "" 40 | } 41 | 42 | // Structs is a struct with the same name as its package. 43 | type Structs struct{} 44 | 45 | func (_ *Structs) M() { 46 | } 47 | -------------------------------------------------------------------------------- /bind/testdata/structs.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI function headers for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java structs 6 | 7 | #ifndef __Structs_H__ 8 | #define __Structs_H__ 9 | 10 | #include 11 | 12 | extern jclass proxy_class_structs_I; 13 | extern jmethodID proxy_class_structs_I_cons; 14 | 15 | void cproxystructs_I_M(int32_t refnum); 16 | 17 | extern jclass proxy_class_structs_S; 18 | extern jmethodID proxy_class_structs_S_cons; 19 | extern jclass proxy_class_structs_S2; 20 | extern jmethodID proxy_class_structs_S2_cons; 21 | extern jclass proxy_class_structs_Structs; 22 | extern jmethodID proxy_class_structs_Structs_cons; 23 | #endif 24 | -------------------------------------------------------------------------------- /bind/testdata/structs.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to structs Go package. 2 | // gobind -lang=objc structs 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO_structs_H__ 7 | #define __GO_structs_H__ 8 | 9 | #include 10 | #include 11 | void cproxystructs_I_M(int32_t refnum); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /bind/testdata/structs.objc.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to structs Go package. 2 | // gobind -lang=objc structs 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __Structs_H__ 7 | #define __Structs_H__ 8 | 9 | @import Foundation; 10 | #include "ref.h" 11 | #include "Universe.objc.h" 12 | 13 | 14 | @class StructsS; 15 | @class StructsS2; 16 | @class StructsStructs; 17 | @protocol StructsI; 18 | @class StructsI; 19 | 20 | @protocol StructsI 21 | - (void)m; 22 | @end 23 | 24 | @interface StructsS : NSObject { 25 | } 26 | @property(strong, readonly) _Nonnull id _ref; 27 | 28 | - (nonnull instancetype)initWithRef:(_Nonnull id)ref; 29 | - (nonnull instancetype)init; 30 | @property (nonatomic) double x; 31 | @property (nonatomic) double y; 32 | - (StructsS* _Nullable)identity:(NSError* _Nullable* _Nullable)error; 33 | - (double)sum; 34 | @end 35 | 36 | @interface StructsS2 : NSObject { 37 | } 38 | @property(strong, readonly) _Nonnull id _ref; 39 | 40 | - (nonnull instancetype)initWithRef:(_Nonnull id)ref; 41 | - (nonnull instancetype)init; 42 | - (void)m; 43 | - (NSString* _Nonnull)string; 44 | @end 45 | 46 | /** 47 | * Structs is a struct with the same name as its package. 48 | */ 49 | @interface StructsStructs : NSObject { 50 | } 51 | @property(strong, readonly) _Nonnull id _ref; 52 | 53 | - (nonnull instancetype)initWithRef:(_Nonnull id)ref; 54 | - (nonnull instancetype)init; 55 | - (void)m; 56 | @end 57 | 58 | FOUNDATION_EXPORT StructsS* _Nullable StructsIdentity(StructsS* _Nullable s); 59 | 60 | FOUNDATION_EXPORT StructsS* _Nullable StructsIdentityWithError(StructsS* _Nullable s, NSError* _Nullable* _Nullable error); 61 | 62 | @class StructsI; 63 | 64 | @interface StructsI : NSObject { 65 | } 66 | @property(strong, readonly) _Nonnull id _ref; 67 | 68 | - (nonnull instancetype)initWithRef:(_Nonnull id)ref; 69 | - (void)m; 70 | @end 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /bind/testdata/testpkg/assets/hello.txt: -------------------------------------------------------------------------------- 1 | Hello, Assets. 2 | -------------------------------------------------------------------------------- /bind/testdata/testpkg/javapkg/java.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package javapkg 6 | 7 | import ( 8 | "Java/java/lang/Float" 9 | "Java/java/lang/Integer" 10 | "Java/java/lang/System" 11 | "Java/java/util/Collections" 12 | "Java/java/util/jar/JarFile" 13 | "fmt" 14 | ) 15 | 16 | func SystemCurrentTimeMillis() int64 { 17 | return System.CurrentTimeMillis() 18 | } 19 | 20 | func FloatMin() float32 { 21 | return Float.MIN_VALUE 22 | } 23 | 24 | func ManifestName() string { 25 | return JarFile.MANIFEST_NAME 26 | } 27 | 28 | func IntegerBytes() int { 29 | return Integer.SIZE 30 | } 31 | 32 | func IntegerValueOf(v int32) int32 { 33 | i, _ := Integer.ValueOf(v) 34 | return i.IntValue() 35 | } 36 | 37 | func IntegerDecode(v string) (int32, error) { 38 | i, err := Integer.Decode(v) 39 | if err != nil { 40 | return 0, fmt.Errorf("wrapped error: %v", err) 41 | } 42 | // Call methods from super class 43 | i.HashCode() 44 | return i.IntValue(), nil 45 | } 46 | 47 | func IntegerParseInt(v string, radix int32) (int32, error) { 48 | return Integer.ParseInt(v, radix) 49 | } 50 | 51 | func ProvokeRuntimeException() (err error) { 52 | defer func() { 53 | err = recover().(error) 54 | }() 55 | Collections.Copy(nil, nil) 56 | return 57 | } 58 | -------------------------------------------------------------------------------- /bind/testdata/testpkg/objcpkg/classes.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package objcpkg 6 | 7 | import ( 8 | "ObjC/Foundation" 9 | gopkg "ObjC/Objcpkg" 10 | "ObjC/UIKit" 11 | ) 12 | 13 | const ( 14 | DescriptionStr = "Descriptrion from Go" 15 | Hash = 42 16 | ) 17 | 18 | type GoNSDate struct { 19 | Foundation.NSDate 20 | } 21 | 22 | func (d *GoNSDate) Hash(self gopkg.GoNSDate) int { 23 | return Hash 24 | } 25 | 26 | func (d *GoNSDate) Description(self gopkg.GoNSDate) string { 27 | // Test self call 28 | if h := self.Hash(); h != Hash { 29 | panic("hash mismatch") 30 | } 31 | return DescriptionStr 32 | } 33 | 34 | func (d *GoNSDate) GetSelf(self gopkg.GoNSDate) Foundation.NSDate { 35 | return self 36 | } 37 | 38 | func NewGoNSDate() *GoNSDate { 39 | return new(GoNSDate) 40 | } 41 | 42 | type GoNSObject struct { 43 | C Foundation.NSObjectC // The class 44 | P Foundation.NSObjectP // The protocol 45 | UseSelf bool 46 | } 47 | 48 | func (o *GoNSObject) Description(self gopkg.GoNSObject) string { 49 | if o.UseSelf { 50 | return DescriptionStr 51 | } else { 52 | return self.Super().Description() 53 | } 54 | } 55 | 56 | func DupNSDate(date Foundation.NSDate) Foundation.NSDate { 57 | return date 58 | } 59 | 60 | type GoUIResponder struct { 61 | UIKit.UIResponder 62 | Called bool 63 | } 64 | 65 | func (r *GoUIResponder) PressesBegan(_ Foundation.NSSet, _ UIKit.UIPressesEvent) { 66 | r.Called = true 67 | } 68 | 69 | // Check that implicitly referenced types are wrapped. 70 | func implicitType(r UIKit.UIResponder) { 71 | r.MotionBegan(0, nil) 72 | } 73 | -------------------------------------------------------------------------------- /bind/testdata/testpkg/objcpkg/objc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package objcpkg 6 | 7 | import ( 8 | "ObjC/Foundation/NSDate" 9 | "ObjC/Foundation/NSString" 10 | "ObjC/QuartzCore/CAMediaTimingFunction" 11 | ) 12 | 13 | func Func() { 14 | NSDate.Date() 15 | CAMediaTimingFunction.FunctionWithControlPoints(0, 0, 0, 0) 16 | } 17 | 18 | func Method() string { 19 | d := NSDate.Date() 20 | return d.Description() 21 | } 22 | 23 | func New() { 24 | NSDate.New() 25 | CAMediaTimingFunction.NewWithControlPoints(0, 0, 0, 0) 26 | } 27 | 28 | func Error() { 29 | str, err := NSString.StringWithContentsOfFileEncodingError("", 0) 30 | if err == nil { 31 | panic("no error from stringWithContentsOfFile") 32 | } 33 | // Assert err is an error 34 | err = err.(error) 35 | if str != "" { 36 | panic("non-empty string from stringWithContentsOfFile") 37 | } 38 | str, err = NSString.NewWithContentsOfFileEncodingError("", 0) 39 | if err == nil { 40 | panic("no error from stringWithContentsOfFile") 41 | } 42 | // Assert err is an error 43 | err = err.(error) 44 | if str != "" { 45 | panic("non-empty string from initWithContentsOfFile") 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /bind/testdata/testpkg/secondpkg/secondpkg.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package secondpkg is imported by bind tests that verify 6 | // that a bound package can reference another bound package. 7 | package secondpkg 8 | 9 | type ( 10 | Ser interface { 11 | S(_ *S) 12 | } 13 | 14 | IF interface { 15 | F() 16 | } 17 | 18 | I interface { 19 | F(i int) int 20 | } 21 | 22 | S struct{} 23 | ) 24 | 25 | func (_ *S) F(i int) int { 26 | return i 27 | } 28 | 29 | const HelloString = "secondpkg string" 30 | 31 | func Hello() string { 32 | return HelloString 33 | } 34 | 35 | type Secondpkg struct { 36 | V string 37 | } 38 | 39 | func (_ *Secondpkg) M() { 40 | } 41 | 42 | func NewSecondpkg() *Secondpkg { 43 | return new(Secondpkg) 44 | } 45 | -------------------------------------------------------------------------------- /bind/testdata/testpkg/simplepkg/simplepkg.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package simplepkg is imported from testpkg and tests two 6 | // corner cases. 7 | // First: simplepkg itself contains no (exported) functions 8 | // or methods and so its generated Go package must not import 9 | // it. 10 | // 11 | // Second: even though testpkg imports simplepkg, testpkg's 12 | // generated Go package ends up not referencing simplepkg and 13 | // must not import it. 14 | package simplepkg 15 | 16 | type S struct{} 17 | -------------------------------------------------------------------------------- /bind/testdata/testpkg/tagged.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build aaa && bbb 6 | 7 | // This file tests that tags work with gomobile. 8 | package testpkg 9 | 10 | const TaggedConst = 42 11 | -------------------------------------------------------------------------------- /bind/testdata/testpkg/unboundpkg/unboundpkg.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package simplepkg is imported from testpkg and tests 6 | // that references to other, unbound packages, are ignored. 7 | package unboundpkg 8 | 9 | type ( 10 | S struct{} 11 | I interface{} 12 | ) 13 | -------------------------------------------------------------------------------- /bind/testdata/try.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package try has a name that is a Java keyword. 6 | // Gobind has to translate it usefully. See Issue #12273. 7 | package try 8 | 9 | func This() string { return "This" } 10 | -------------------------------------------------------------------------------- /bind/testdata/try.go.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // Package main is an autogenerated binder stub for package try. 4 | // 5 | // autogenerated by gobind -lang=go try 6 | package main 7 | 8 | /* 9 | #include 10 | #include 11 | #include "seq.h" 12 | #include "try.h" 13 | 14 | */ 15 | import "C" 16 | 17 | import ( 18 | _seq "golang.org/x/mobile/bind/seq" 19 | "try" 20 | ) 21 | 22 | // suppress the error if seq ends up unused 23 | var _ = _seq.FromRefNum 24 | 25 | //export proxytry__This 26 | func proxytry__This() C.nstring { 27 | res_0 := try.This() 28 | _res_0 := encodeString(res_0) 29 | return _res_0 30 | } 31 | -------------------------------------------------------------------------------- /bind/testdata/try.java.c.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI functions for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java try 6 | 7 | #include 8 | #include 9 | #include "seq.h" 10 | #include "_cgo_export.h" 11 | #include "try.h" 12 | 13 | 14 | JNIEXPORT void JNICALL 15 | Java_try_1_Try__1init(JNIEnv *env, jclass _unused) { 16 | jclass clazz; 17 | } 18 | 19 | JNIEXPORT jstring JNICALL 20 | Java_try_1_Try_this_1(JNIEnv* env, jclass _clazz) { 21 | nstring r0 = proxytry__This(); 22 | jstring _r0 = go_seq_to_java_string(env, r0); 23 | return _r0; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /bind/testdata/try.java.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // Java class try_.Try is a proxy for talking to a Go program. 4 | // 5 | // autogenerated by gobind -lang=java try 6 | package try_; 7 | 8 | import go.Seq; 9 | 10 | public abstract class Try { 11 | static { 12 | Seq.touch(); // for loading the native library 13 | _init(); 14 | } 15 | 16 | private Try() {} // uninstantiable 17 | 18 | // touch is called from other bound packages to initialize this package 19 | public static void touch() {} 20 | 21 | private static native void _init(); 22 | 23 | 24 | 25 | public static native String this_(); 26 | } 27 | -------------------------------------------------------------------------------- /bind/testdata/try.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI function headers for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java try 6 | 7 | #ifndef __Try_H__ 8 | #define __Try_H__ 9 | 10 | #include 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /bind/testdata/try.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to try Go package. 2 | // gobind -lang=objc try 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO_try_H__ 7 | #define __GO_try_H__ 8 | 9 | #include 10 | #include 11 | #endif 12 | -------------------------------------------------------------------------------- /bind/testdata/try.objc.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to try Go package. 2 | // gobind -lang=objc try 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __Try_H__ 7 | #define __Try_H__ 8 | 9 | @import Foundation; 10 | #include "ref.h" 11 | #include "Universe.objc.h" 12 | 13 | 14 | FOUNDATION_EXPORT NSString* _Nonnull TryThis(void); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /bind/testdata/try.objc.m.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to try Go package. 2 | // gobind -lang=objc try 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #include 7 | #include "seq.h" 8 | #include "_cgo_export.h" 9 | #include "Try.objc.h" 10 | 11 | 12 | NSString* _Nonnull TryThis(void) { 13 | nstring r0 = proxytry__This(); 14 | NSString *_ret0_ = go_seq_to_objc_string(r0); 15 | return _ret0_; 16 | } 17 | 18 | __attribute__((constructor)) static void init() { 19 | init_seq(); 20 | } 21 | -------------------------------------------------------------------------------- /bind/testdata/underscores.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package underscore_pkg 6 | 7 | type Underscore_struct struct { 8 | Underscore_field string 9 | } 10 | 11 | var Underscore_var int 12 | 13 | func Underscore_func() {} 14 | -------------------------------------------------------------------------------- /bind/testdata/underscores.go.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // Package main is an autogenerated binder stub for package underscore_pkg. 4 | // 5 | // autogenerated by gobind -lang=go underscores 6 | package main 7 | 8 | /* 9 | #include 10 | #include 11 | #include "seq.h" 12 | #include "underscore_pkg.h" 13 | 14 | */ 15 | import "C" 16 | 17 | import ( 18 | _seq "golang.org/x/mobile/bind/seq" 19 | "underscores" 20 | ) 21 | 22 | // suppress the error if seq ends up unused 23 | var _ = _seq.FromRefNum 24 | 25 | //export proxyunderscore_pkg_Underscore_struct_Underscore_field_Set 26 | func proxyunderscore_pkg_Underscore_struct_Underscore_field_Set(refnum C.int32_t, v C.nstring) { 27 | ref := _seq.FromRefNum(int32(refnum)) 28 | _v := decodeString(v) 29 | ref.Get().(*underscore_pkg.Underscore_struct).Underscore_field = _v 30 | } 31 | 32 | //export proxyunderscore_pkg_Underscore_struct_Underscore_field_Get 33 | func proxyunderscore_pkg_Underscore_struct_Underscore_field_Get(refnum C.int32_t) C.nstring { 34 | ref := _seq.FromRefNum(int32(refnum)) 35 | v := ref.Get().(*underscore_pkg.Underscore_struct).Underscore_field 36 | _v := encodeString(v) 37 | return _v 38 | } 39 | 40 | //export new_underscore_pkg_Underscore_struct 41 | func new_underscore_pkg_Underscore_struct() C.int32_t { 42 | return C.int32_t(_seq.ToRefNum(new(underscore_pkg.Underscore_struct))) 43 | } 44 | 45 | //export var_setunderscore_pkg_Underscore_var 46 | func var_setunderscore_pkg_Underscore_var(v C.nint) { 47 | _v := int(v) 48 | underscore_pkg.Underscore_var = _v 49 | } 50 | 51 | //export var_getunderscore_pkg_Underscore_var 52 | func var_getunderscore_pkg_Underscore_var() C.nint { 53 | v := underscore_pkg.Underscore_var 54 | _v := C.nint(v) 55 | return _v 56 | } 57 | 58 | //export proxyunderscore_pkg__Underscore_func 59 | func proxyunderscore_pkg__Underscore_func() { 60 | underscore_pkg.Underscore_func() 61 | } 62 | -------------------------------------------------------------------------------- /bind/testdata/underscores.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI function headers for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java underscores 6 | 7 | #ifndef __Underscore_pkg_H__ 8 | #define __Underscore_pkg_H__ 9 | 10 | #include 11 | 12 | extern jclass proxy_class_underscore_pkg_Underscore_struct; 13 | extern jmethodID proxy_class_underscore_pkg_Underscore_struct_cons; 14 | #endif 15 | -------------------------------------------------------------------------------- /bind/testdata/underscores.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to underscores Go package. 2 | // gobind -lang=objc underscores 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO_underscore_pkg_H__ 7 | #define __GO_underscore_pkg_H__ 8 | 9 | #include 10 | #include 11 | #endif 12 | -------------------------------------------------------------------------------- /bind/testdata/underscores.objc.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to underscores Go package. 2 | // gobind -lang=objc underscores 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __Underscore_pkg_H__ 7 | #define __Underscore_pkg_H__ 8 | 9 | @import Foundation; 10 | #include "ref.h" 11 | #include "Universe.objc.h" 12 | 13 | 14 | @class Underscore_pkgUnderscore_struct; 15 | 16 | @interface Underscore_pkgUnderscore_struct : NSObject { 17 | } 18 | @property(strong, readonly) _Nonnull id _ref; 19 | 20 | - (nonnull instancetype)initWithRef:(_Nonnull id)ref; 21 | - (nonnull instancetype)init; 22 | @property (nonatomic) NSString* _Nonnull underscore_field; 23 | @end 24 | 25 | @interface Underscore_pkg : NSObject 26 | + (long) underscore_var; 27 | + (void) setUnderscore_var:(long)v; 28 | 29 | @end 30 | 31 | FOUNDATION_EXPORT void Underscore_pkgUnderscore_func(void); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /bind/testdata/underscores.objc.m.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to underscores Go package. 2 | // gobind -lang=objc underscores 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #include 7 | #include "seq.h" 8 | #include "_cgo_export.h" 9 | #include "Underscore_pkg.objc.h" 10 | 11 | 12 | @implementation Underscore_pkgUnderscore_struct { 13 | } 14 | 15 | - (nonnull instancetype)initWithRef:(_Nonnull id)ref { 16 | self = [super init]; 17 | if (self) { __ref = ref; } 18 | return self; 19 | } 20 | 21 | - (nonnull instancetype)init { 22 | self = [super init]; 23 | if (self) { 24 | __ref = go_seq_from_refnum(new_underscore_pkg_Underscore_struct()); 25 | } 26 | return self; 27 | } 28 | 29 | - (NSString* _Nonnull)underscore_field { 30 | int32_t refnum = go_seq_go_to_refnum(self._ref); 31 | nstring r0 = proxyunderscore_pkg_Underscore_struct_Underscore_field_Get(refnum); 32 | NSString *_r0 = go_seq_to_objc_string(r0); 33 | return _r0; 34 | } 35 | 36 | - (void)setUnderscore_field:(NSString* _Nonnull)v { 37 | int32_t refnum = go_seq_go_to_refnum(self._ref); 38 | nstring _v = go_seq_from_objc_string(v); 39 | proxyunderscore_pkg_Underscore_struct_Underscore_field_Set(refnum, _v); 40 | } 41 | 42 | @end 43 | 44 | 45 | @implementation Underscore_pkg 46 | + (void) setUnderscore_var:(long)v { 47 | nint _v = (nint)v; 48 | var_setunderscore_pkg_Underscore_var(_v); 49 | } 50 | 51 | + (long) underscore_var { 52 | nint r0 = var_getunderscore_pkg_Underscore_var(); 53 | long _r0 = (long)r0; 54 | return _r0; 55 | } 56 | 57 | @end 58 | 59 | 60 | void Underscore_pkgUnderscore_func(void) { 61 | proxyunderscore_pkg__Underscore_func(); 62 | } 63 | 64 | __attribute__((constructor)) static void init() { 65 | init_seq(); 66 | } 67 | -------------------------------------------------------------------------------- /bind/testdata/universe.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // Package main is an autogenerated binder stub for package universe. 4 | // 5 | // autogenerated by gobind -lang=go 6 | package main 7 | 8 | /* 9 | #include 10 | #include 11 | #include "seq.h" 12 | #include "universe.h" 13 | 14 | */ 15 | import "C" 16 | 17 | import ( 18 | _seq "golang.org/x/mobile/bind/seq" 19 | ) 20 | 21 | // suppress the error if seq ends up unused 22 | var _ = _seq.FromRefNum 23 | 24 | //export proxy_error_Error 25 | func proxy_error_Error(refnum C.int32_t) C.nstring { 26 | ref := _seq.FromRefNum(int32(refnum)) 27 | v := ref.Get().(error) 28 | res_0 := v.Error() 29 | _res_0 := encodeString(res_0) 30 | return _res_0 31 | } 32 | 33 | type proxy_error _seq.Ref 34 | 35 | func (p *proxy_error) Bind_proxy_refnum__() int32 { 36 | return (*_seq.Ref)(p).Bind_IncNum() 37 | } 38 | 39 | func (p *proxy_error) Error() string { 40 | res := C.cproxy_error_Error(C.int32_t(p.Bind_proxy_refnum__())) 41 | _res := decodeString(res) 42 | return _res 43 | } 44 | -------------------------------------------------------------------------------- /bind/testdata/universe.java.c.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI functions for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java 6 | 7 | #include 8 | #include 9 | #include "seq.h" 10 | #include "_cgo_export.h" 11 | #include "universe.h" 12 | 13 | jclass proxy_class__error; 14 | jmethodID proxy_class__error_cons; 15 | static jmethodID mid_error_Error; 16 | 17 | JNIEXPORT void JNICALL 18 | Java_go_Universe__1init(JNIEnv *env, jclass _unused) { 19 | jclass clazz; 20 | clazz = (*env)->FindClass(env, "go/Universe$proxyerror"); 21 | proxy_class__error = (*env)->NewGlobalRef(env, clazz); 22 | proxy_class__error_cons = (*env)->GetMethodID(env, clazz, "", "(I)V"); 23 | clazz = (*env)->FindClass(env, "java/lang/Throwable"); 24 | mid_error_Error = (*env)->GetMethodID(env, clazz, "getMessage", "()Ljava/lang/String;"); 25 | } 26 | 27 | JNIEXPORT jstring JNICALL 28 | Java_go_Universe_00024proxyerror_error(JNIEnv* env, jobject __this__) { 29 | int32_t o = go_seq_to_refnum_go(env, __this__); 30 | nstring r0 = proxy_error_Error(o); 31 | jstring _r0 = go_seq_to_java_string(env, r0); 32 | return _r0; 33 | } 34 | 35 | nstring cproxy_error_Error(int32_t refnum) { 36 | JNIEnv *env = go_seq_push_local_frame(0); 37 | jobject o = go_seq_from_refnum(env, refnum, proxy_class__error, proxy_class__error_cons); 38 | jstring res = (*env)->CallObjectMethod(env, o, mid_error_Error); 39 | nstring _res = go_seq_from_java_string(env, res); 40 | go_seq_pop_local_frame(env); 41 | return _res; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /bind/testdata/universe.java.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // Java class go.error is a proxy for talking to a Go program. 4 | // 5 | // autogenerated by gobind -lang=java 6 | package go; 7 | 8 | import go.Seq; 9 | 10 | public interface error { 11 | public String error(); 12 | 13 | } 14 | 15 | // Code generated by gobind. DO NOT EDIT. 16 | 17 | // Java class go.Universe is a proxy for talking to a Go program. 18 | // 19 | // autogenerated by gobind -lang=java 20 | package go; 21 | 22 | import go.Seq; 23 | 24 | public abstract class Universe { 25 | static { 26 | Seq.touch(); // for loading the native library 27 | _init(); 28 | } 29 | 30 | private Universe() {} // uninstantiable 31 | 32 | // touch is called from other bound packages to initialize this package 33 | public static void touch() {} 34 | 35 | private static native void _init(); 36 | 37 | private static final class proxyerror extends Exception implements Seq.Proxy, error { 38 | private final int refnum; 39 | 40 | @Override public final int incRefnum() { 41 | Seq.incGoRef(refnum, this); 42 | return refnum; 43 | } 44 | 45 | proxyerror(int refnum) { this.refnum = refnum; Seq.trackGoRef(refnum, this); } 46 | 47 | @Override public String getMessage() { return error(); } 48 | 49 | public native String error(); 50 | } 51 | 52 | 53 | } 54 | -------------------------------------------------------------------------------- /bind/testdata/universe.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI function headers for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java 6 | 7 | #ifndef __Universe_H__ 8 | #define __Universe_H__ 9 | 10 | #include 11 | 12 | extern jclass proxy_class__error; 13 | extern jmethodID proxy_class__error_cons; 14 | 15 | nstring cproxy_error_Error(int32_t refnum); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /bind/testdata/universe.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to Go package. 2 | // gobind -lang=objc 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO__H__ 7 | #define __GO__H__ 8 | 9 | #include 10 | #include 11 | nstring cproxy_error_Error(int32_t refnum); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /bind/testdata/universe.objc.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to Go package. 2 | // gobind -lang=objc 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __Universe_H__ 7 | #define __Universe_H__ 8 | 9 | @import Foundation; 10 | #include "ref.h" 11 | 12 | @protocol Universeerror; 13 | @class Universeerror; 14 | 15 | @protocol Universeerror 16 | - (NSString* _Nonnull)error; 17 | @end 18 | 19 | @class Universeerror; 20 | 21 | @interface Universeerror : NSError { 22 | } 23 | @property(strong, readonly) _Nonnull id _ref; 24 | 25 | - (nonnull instancetype)initWithRef:(_Nonnull id)ref; 26 | - (NSString* _Nonnull)error; 27 | @end 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /bind/testdata/universe.objc.m.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to Go package. 2 | // gobind -lang=objc 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #include 7 | #include "seq.h" 8 | #include "_cgo_export.h" 9 | #include "Universe.objc.h" 10 | 11 | @implementation Universeerror { 12 | } 13 | 14 | - (nonnull instancetype)initWithRef:(id)ref { 15 | if (self) { 16 | __ref = ref; 17 | self = [super initWithDomain:@"go" code:1 userInfo:@{NSLocalizedDescriptionKey: [self error]}]; 18 | } 19 | return self; 20 | } 21 | 22 | - (NSString* _Nonnull)error { 23 | int32_t refnum = go_seq_go_to_refnum(self._ref); 24 | nstring r0 = proxy_error_Error(refnum); 25 | NSString *_ret0_ = go_seq_to_objc_string(r0); 26 | return _ret0_; 27 | } 28 | 29 | @end 30 | 31 | 32 | 33 | nstring cproxy_error_Error(int32_t refnum) { 34 | @autoreleasepool { 35 | Universeerror* o = go_seq_objc_from_refnum(refnum); 36 | NSString* _Nonnull ret0_; 37 | ret0_ = [o localizedDescription]; 38 | nstring _ret0_ = go_seq_from_objc_string(ret0_); 39 | return _ret0_; 40 | } 41 | } 42 | 43 | __attribute__((constructor)) static void init() { 44 | init_seq(); 45 | } 46 | -------------------------------------------------------------------------------- /bind/testdata/vars.go: -------------------------------------------------------------------------------- 1 | package vars 2 | 3 | var ( 4 | AString = "String" 5 | 6 | AnInt = -1 7 | AnInt8 int8 = 8 8 | AnInt16 int16 = 16 9 | AnInt32 int32 = 32 10 | AnInt64 int64 = 64 11 | 12 | AFloat = -2.0 13 | AFloat32 float32 = 32.0 14 | AFloat64 float64 = 64.0 15 | 16 | ABool = true 17 | 18 | AStructPtr *S 19 | AnInterface I 20 | ) 21 | 22 | type S struct{} 23 | 24 | type I interface{} 25 | -------------------------------------------------------------------------------- /bind/testdata/vars.java.h.golden: -------------------------------------------------------------------------------- 1 | // Code generated by gobind. DO NOT EDIT. 2 | 3 | // JNI function headers for the Go <=> Java bridge. 4 | // 5 | // autogenerated by gobind -lang=java vars 6 | 7 | #ifndef __Vars_H__ 8 | #define __Vars_H__ 9 | 10 | #include 11 | 12 | extern jclass proxy_class_vars_I; 13 | extern jmethodID proxy_class_vars_I_cons; 14 | 15 | extern jclass proxy_class_vars_S; 16 | extern jmethodID proxy_class_vars_S_cons; 17 | #endif 18 | -------------------------------------------------------------------------------- /bind/testdata/vars.objc.go.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to vars Go package. 2 | // gobind -lang=objc vars 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __GO_vars_H__ 7 | #define __GO_vars_H__ 8 | 9 | #include 10 | #include 11 | #endif 12 | -------------------------------------------------------------------------------- /bind/testdata/vars.objc.h.golden: -------------------------------------------------------------------------------- 1 | // Objective-C API for talking to vars Go package. 2 | // gobind -lang=objc vars 3 | // 4 | // File is generated by gobind. Do not edit. 5 | 6 | #ifndef __Vars_H__ 7 | #define __Vars_H__ 8 | 9 | @import Foundation; 10 | #include "ref.h" 11 | #include "Universe.objc.h" 12 | 13 | 14 | @class VarsS; 15 | @protocol VarsI; 16 | @class VarsI; 17 | 18 | @protocol VarsI 19 | @end 20 | 21 | @interface VarsS : NSObject { 22 | } 23 | @property(strong, readonly) _Nonnull id _ref; 24 | 25 | - (nonnull instancetype)initWithRef:(_Nonnull id)ref; 26 | - (nonnull instancetype)init; 27 | @end 28 | 29 | @interface Vars : NSObject 30 | + (BOOL) aBool; 31 | + (void) setABool:(BOOL)v; 32 | 33 | + (double) aFloat; 34 | + (void) setAFloat:(double)v; 35 | 36 | + (float) aFloat32; 37 | + (void) setAFloat32:(float)v; 38 | 39 | + (double) aFloat64; 40 | + (void) setAFloat64:(double)v; 41 | 42 | + (NSString* _Nonnull) aString; 43 | + (void) setAString:(NSString* _Nonnull)v; 44 | 45 | + (VarsS* _Nullable) aStructPtr; 46 | + (void) setAStructPtr:(VarsS* _Nullable)v; 47 | 48 | + (long) anInt; 49 | + (void) setAnInt:(long)v; 50 | 51 | + (int16_t) anInt16; 52 | + (void) setAnInt16:(int16_t)v; 53 | 54 | + (int32_t) anInt32; 55 | + (void) setAnInt32:(int32_t)v; 56 | 57 | + (int64_t) anInt64; 58 | + (void) setAnInt64:(int64_t)v; 59 | 60 | + (int8_t) anInt8; 61 | + (void) setAnInt8:(int8_t)v; 62 | 63 | + (id _Nullable) anInterface; 64 | + (void) setAnInterface:(id _Nullable)v; 65 | 66 | @end 67 | 68 | @class VarsI; 69 | 70 | @interface VarsI : NSObject { 71 | } 72 | @property(strong, readonly) _Nonnull id _ref; 73 | 74 | - (nonnull instancetype)initWithRef:(_Nonnull id)ref; 75 | @end 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /cmd/gobind/implicit.go: -------------------------------------------------------------------------------- 1 | // This file imports implicit dependencies required by generated code. 2 | 3 | //go:build mobile_implicit 4 | 5 | package main 6 | 7 | import ( 8 | _ "golang.org/x/mobile/bind" 9 | _ "golang.org/x/mobile/bind/java" 10 | _ "golang.org/x/mobile/bind/objc" 11 | ) 12 | -------------------------------------------------------------------------------- /cmd/gomobile/clean.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "fmt" 9 | "path/filepath" 10 | ) 11 | 12 | var cmdClean = &command{ 13 | run: runClean, 14 | Name: "clean", 15 | Usage: "", 16 | Short: "remove object files and cached gomobile files", 17 | Long: ` 18 | Clean removes object files and cached NDK files downloaded by gomobile init 19 | `, 20 | } 21 | 22 | func runClean(cmd *command) (err error) { 23 | gopaths := filepath.SplitList(goEnv("GOPATH")) 24 | if len(gopaths) == 0 { 25 | return fmt.Errorf("GOPATH is not set") 26 | } 27 | gomobilepath = filepath.Join(gopaths[0], "pkg/gomobile") 28 | if buildX { 29 | fmt.Fprintln(xout, "GOMOBILE="+gomobilepath) 30 | } 31 | return removeAll(gomobilepath) 32 | } 33 | -------------------------------------------------------------------------------- /cmd/gomobile/install.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "fmt" 9 | "os" 10 | "os/exec" 11 | "path" 12 | "strings" 13 | ) 14 | 15 | var cmdInstall = &command{ 16 | run: runInstall, 17 | Name: "install", 18 | Usage: "[-target android] [build flags] [package]", 19 | Short: "compile android APK and install on device", 20 | Long: ` 21 | Install compiles and installs the app named by the import path on the 22 | attached mobile device. 23 | 24 | Only -target android is supported. The 'adb' tool must be on the PATH. 25 | 26 | The build flags -a, -i, -n, -x, -gcflags, -ldflags, -tags, -trimpath, and -work are 27 | shared with the build command. 28 | For documentation, see 'go help build'. 29 | `, 30 | } 31 | 32 | func runInstall(cmd *command) error { 33 | if !strings.HasPrefix(buildTarget, "android") { 34 | return fmt.Errorf("install is not supported for -target=%s", buildTarget) 35 | } 36 | pkg, err := runBuildImpl(cmd) 37 | if err != nil { 38 | return err 39 | } 40 | 41 | // Don't use runCmd as adb does not return a useful exit code. 42 | c := exec.Command( 43 | `adb`, 44 | `install`, 45 | `-r`, 46 | androidPkgName(path.Base(pkg.PkgPath))+`.apk`, 47 | ) 48 | c.Stdout = os.Stdout 49 | c.Stderr = os.Stderr 50 | if buildX || buildN { 51 | printcmd("%s", strings.Join(c.Args, " ")) 52 | } 53 | if buildN { 54 | return nil 55 | } 56 | return c.Run() 57 | } 58 | -------------------------------------------------------------------------------- /cmd/gomobile/strings_flag.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import "fmt" 8 | 9 | type stringsFlag []string 10 | 11 | func (v *stringsFlag) Set(s string) error { 12 | var err error 13 | *v, err = splitQuotedFields(s) 14 | if *v == nil { 15 | *v = []string{} 16 | } 17 | return err 18 | } 19 | 20 | func isSpaceByte(c byte) bool { 21 | return c == ' ' || c == '\t' || c == '\n' || c == '\r' 22 | } 23 | 24 | func splitQuotedFields(s string) ([]string, error) { 25 | // Split fields allowing '' or "" around elements. 26 | // Quotes further inside the string do not count. 27 | var f []string 28 | for len(s) > 0 { 29 | for len(s) > 0 && isSpaceByte(s[0]) { 30 | s = s[1:] 31 | } 32 | if len(s) == 0 { 33 | break 34 | } 35 | // Accepted quoted string. No unescaping inside. 36 | if s[0] == '"' || s[0] == '\'' { 37 | quote := s[0] 38 | s = s[1:] 39 | i := 0 40 | for i < len(s) && s[i] != quote { 41 | i++ 42 | } 43 | if i >= len(s) { 44 | return nil, fmt.Errorf("unterminated %c string", quote) 45 | } 46 | f = append(f, s[:i]) 47 | s = s[i+1:] 48 | continue 49 | } 50 | i := 0 51 | for i < len(s) && !isSpaceByte(s[i]) { 52 | i++ 53 | } 54 | f = append(f, s[:i]) 55 | s = s[i:] 56 | } 57 | return f, nil 58 | } 59 | 60 | func (v *stringsFlag) String() string { 61 | return "" 62 | } 63 | -------------------------------------------------------------------------------- /cmd/gomobile/tools.go: -------------------------------------------------------------------------------- 1 | // This file includes the tools the gomobile depends on. 2 | 3 | //go:build tools 4 | 5 | package main 6 | 7 | import ( 8 | _ "golang.org/x/mobile/cmd/gobind" 9 | ) 10 | -------------------------------------------------------------------------------- /codereview.cfg: -------------------------------------------------------------------------------- 1 | issuerepo: golang/go 2 | -------------------------------------------------------------------------------- /doc/caution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/doc/caution.png -------------------------------------------------------------------------------- /event/paint/paint.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package paint defines an event for the app being ready to paint. 6 | // 7 | // See the golang.org/x/mobile/app package for details on the event model. 8 | package paint 9 | 10 | // Event indicates that the app is ready to paint the next frame of the GUI. 11 | // 12 | // A frame is completed by calling the App's Publish method. 13 | type Event struct { 14 | // External is true for paint events sent by the screen driver. 15 | // 16 | // An external event may be sent at any time in response to an 17 | // operating system event, for example the window opened, was 18 | // resized, or the screen memory was lost. 19 | // 20 | // Programs actively drawing to the screen as fast as vsync allows 21 | // should ignore external paint events to avoid a backlog of paint 22 | // events building up. 23 | External bool 24 | } 25 | -------------------------------------------------------------------------------- /example/basic/main_x.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !darwin && !linux && !windows 6 | 7 | package main 8 | 9 | func main() { 10 | } 11 | -------------------------------------------------------------------------------- /example/bind/android/README: -------------------------------------------------------------------------------- 1 | Go bind android app example 2 | 3 | Run 4 | 5 | $ gomobile bind -o app/hello.aar golang.org/x/mobile/example/bind/hello 6 | 7 | and import this project in Android Studio. If you prefer the command 8 | line, use gradle to build directly. 9 | 10 | Note that you need to run gomobile bind again every time you make a 11 | change to Go code. 12 | -------------------------------------------------------------------------------- /example/bind/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 The Go Authors. All rights reserved. 3 | * Use of this source code is governed by a BSD-style 4 | * license that can be found in the LICENSE file. 5 | */ 6 | apply plugin: 'com.android.application' 7 | 8 | repositories { 9 | flatDir { 10 | dirs '.' 11 | } 12 | } 13 | 14 | android { 15 | compileSdkVersion 27 16 | 17 | defaultConfig { 18 | applicationId "org.golang.example.android" 19 | minSdkVersion 15 20 | targetSdkVersion 27 21 | versionCode 1 22 | versionName "1.0" 23 | } 24 | buildTypes { 25 | release { 26 | minifyEnabled false 27 | } 28 | } 29 | } 30 | 31 | dependencies { 32 | implementation 'com.android.support:appcompat-v7:22.1.1' 33 | implementation (name:'hello', ext:'aar') 34 | } 35 | -------------------------------------------------------------------------------- /example/bind/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 7 | 8 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /example/bind/android/app/src/main/java/org/golang/example/bind/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 The Go Authors. All rights reserved. 3 | * Use of this source code is governed by a BSD-style 4 | * license that can be found in the LICENSE file. 5 | */ 6 | 7 | package org.golang.example.bind; 8 | 9 | import android.app.Activity; 10 | import android.os.Bundle; 11 | import android.widget.TextView; 12 | 13 | import hello.Hello; 14 | 15 | public class MainActivity extends Activity { 16 | 17 | private TextView mTextView; 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.activity_main); 23 | mTextView = (TextView) findViewById(R.id.mytextview); 24 | 25 | // Call Go function. 26 | String greetings = Hello.greetings("Android and Gopher"); 27 | mTextView.setText(greetings); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /example/bind/android/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 11 | 12 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /example/bind/android/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 16dp 7 | 16dp 8 | 9 | -------------------------------------------------------------------------------- /example/bind/android/build.gradle: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 The Go Authors. All rights reserved. 2 | * Use of this source code is governed by a BSD-style 3 | * license that can be found in the LICENSE file. 4 | */ 5 | 6 | buildscript { 7 | repositories { 8 | google() 9 | jcenter() 10 | } 11 | dependencies { 12 | classpath 'com.android.tools.build:gradle:3.1.0' 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | google() 19 | jcenter() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /example/bind/android/settings.gradle: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 The Go Authors. All rights reserved. 2 | * Use of this source code is governed by a BSD-style 3 | * license that can be found in the LICENSE file. 4 | */ 5 | include ':app' 6 | -------------------------------------------------------------------------------- /example/bind/hello/hello.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package hello is a trivial package for gomobile bind example. 6 | package hello 7 | 8 | import "fmt" 9 | 10 | func Greetings(name string) string { 11 | return fmt.Sprintf("Hello, %s!", name) 12 | } 13 | -------------------------------------------------------------------------------- /example/bind/ios/README: -------------------------------------------------------------------------------- 1 | 1. Use gomobile bind to bind the golang.org/x/mobile/example/bind/hello package. 2 | The following command will create an XCFramework in the current directory. 3 | 4 | $ gomobile bind -target=ios golang.org/x/mobile/example/bind/hello 5 | 6 | 2. Open the Xcode project by double clicking on bind.xcodeproj. 7 | The project will not build - ViewController.m calls a function from the hello 8 | package so requires the Hello.xcframework that gomobile bind command created 9 | in Step 1. 10 | 11 | 3. Drag-and-drop Hello.xcframework from the desktop to the project navigation window. 12 | This will automatically include the Hello.xcframework into the project. 13 | 14 | 4. Build. 15 | -------------------------------------------------------------------------------- /example/bind/ios/bind/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #import 6 | 7 | @interface AppDelegate : UIResponder 8 | @property (strong, nonatomic) UIWindow *window; 9 | @end 10 | 11 | -------------------------------------------------------------------------------- /example/bind/ios/bind/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #import "AppDelegate.h" 6 | 7 | @interface AppDelegate () 8 | @end 9 | 10 | @implementation AppDelegate 11 | 12 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 13 | return YES; 14 | } 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /example/bind/ios/bind/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.golang.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /example/bind/ios/bind/ViewController.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #import 6 | 7 | @interface ViewController : UIViewController 8 | @property (strong, nonatomic) IBOutlet UILabel *textLabel; 9 | @end 10 | -------------------------------------------------------------------------------- /example/bind/ios/bind/ViewController.m: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #import "ViewController.h" 6 | @import Hello; // Gomobile bind generated framework 7 | 8 | @interface ViewController () 9 | @end 10 | 11 | @implementation ViewController 12 | 13 | @synthesize textLabel; 14 | 15 | - (void)loadView { 16 | [super loadView]; 17 | textLabel.text = HelloGreetings(@"iOS and Gopher"); 18 | } 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /example/bind/ios/bind/main.m: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #import 6 | #import "AppDelegate.h" 7 | 8 | int main(int argc, char * argv[]) { 9 | @autoreleasepool { 10 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /example/flappy/assets/README: -------------------------------------------------------------------------------- 1 | The sprites were created by Renee French and are distributed 2 | under the Creative Commons Attributions 3.0 license. 3 | -------------------------------------------------------------------------------- /example/flappy/assets/sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/flappy/assets/sprite.png -------------------------------------------------------------------------------- /example/flappy/main_x.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !darwin && !linux 6 | 7 | package main 8 | 9 | func main() { 10 | } 11 | -------------------------------------------------------------------------------- /example/ivy/android/README.md: -------------------------------------------------------------------------------- 1 | ## Ivy Big Number Calculator (Android) 2 | 3 | [Ivy (robpike.io/ivy)](https://robpike.io/ivy) is an interpreter for an APL-like language written in Go. 4 | This repository hosts a minimal Android project used for its [Android version](https://play.google.com/store/apps/details?id=org.golang.ivy&hl=en_US&gl=US). 5 | 6 | ### How to build 7 | 8 | Requirements 9 | - Go 1.17 or newer 10 | - Android SDK 11 | - Android NDK 12 | - `golang.org/x/mobile/cmd/gomobile` 13 | 14 | The `gomobile` command respects the `ANDROID_HOME` and `ANDROID_NDK_HOME` environment variables. If `gomobile` can't find your SDK and NDK, you can set these environment variables to specify their locations: 15 | ``` 16 | export ANDROID_HOME=/path/to/sdk-directory 17 | export ANDROID_NDK_HOME=/path/to/ndk-directory 18 | ``` 19 | 20 | From this directory, run: 21 | 22 | ```sh 23 | go install golang.org/x/mobile/cmd/gomobile@latest 24 | go install golang.org/x/mobile/cmd/gobind@latest 25 | 26 | # Make sure `gomobile` and `gobind` is in your `PATH`. 27 | gomobile bind -o app/ivy.aar robpike.io/ivy/mobile 28 | ``` 29 | 30 | Open this directory from Android Studio, and build. 31 | 32 | `robpike.io/ivy` and `golang.org/x/mobile` are required dependencies of this main module. In order to update them: 33 | 34 | ``` 35 | go get -d golang.org/x/mobile@latest 36 | go get -d robpike.io/ivy/mobile 37 | go mod tidy 38 | ``` 39 | -------------------------------------------------------------------------------- /example/ivy/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 30 5 | defaultConfig { 6 | applicationId 'org.golang.ivy' 7 | minSdkVersion 15 8 | targetSdkVersion 30 9 | versionCode 4 10 | versionName '1.4.0' 11 | } 12 | buildTypes { 13 | release { 14 | minifyEnabled true 15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 16 | } 17 | } 18 | productFlavors { 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation 'androidx.appcompat:appcompat:1.0.0' 24 | implementation files('ivy.aar') 25 | } 26 | -------------------------------------------------------------------------------- /example/ivy/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/hakim/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/androidTest/java/org/golang/ivy/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package org.golang.ivy; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/assets/aboutivy.html: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 |
9 |

Ivy

10 | 11 | Based on robpike.io/ivy 12 |

13 | Copyright 2015 The Go Authors. 14 |
15 | The Ivy mascot is designed by 16 | Renee French 17 | and licensed under the 18 | Creative Commons Attribution 3.0 license. 19 |

20 | 21 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/assets/tape.html: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 34 | 35 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/java/org/golang/ivy/AboutIvy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 The Go Authors. All rights reserved. 3 | * Use of this source code is governed by a BSD-style 4 | * license that can be found in the LICENSE file. 5 | */ 6 | 7 | package org.golang.ivy; 8 | 9 | import android.content.Intent; 10 | import android.net.Uri; 11 | import android.os.Bundle; 12 | import android.view.LayoutInflater; 13 | import android.view.MenuItem; 14 | import android.view.View; 15 | import android.view.ViewGroup; 16 | import android.webkit.WebView; 17 | import android.webkit.WebViewClient; 18 | 19 | import androidx.appcompat.app.AppCompatActivity; 20 | 21 | /* 22 | * Handles About menu item. 23 | */ 24 | public class AboutIvy extends AppCompatActivity { 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_about); 30 | 31 | LayoutInflater inflater = getLayoutInflater(); 32 | View layout = inflater.inflate(R.layout.activity_about, 33 | (ViewGroup) findViewById(R.id.about_layout)); 34 | 35 | WebView webView = (WebView) layout.findViewById(R.id.about_ivy); 36 | webView.setWebViewClient(new WebViewClient(){ 37 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 38 | if (url != null && (url.startsWith("https://") || url.startsWith("http://"))) { 39 | view.getContext().startActivity( 40 | new Intent(Intent.ACTION_VIEW, Uri.parse(url))); 41 | return true; 42 | } else { 43 | return false; 44 | } 45 | } 46 | }); 47 | webView.getSettings().setDefaultTextEncodingName("utf-8"); 48 | webView.loadUrl("file:///android_asset/aboutivy.html"); 49 | } 50 | 51 | @Override 52 | public boolean onOptionsItemSelected(MenuItem item) { 53 | onBackPressed(); // back to parent. 54 | return true; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/java/org/golang/ivy/Help.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2015 The Go Authors. All rights reserved. 3 | * Use of this source code is governed by a BSD-style 4 | * license that can be found in the LICENSE file. 5 | */ 6 | 7 | package org.golang.ivy; 8 | 9 | 10 | import android.content.Intent; 11 | import android.net.Uri; 12 | import android.os.Bundle; 13 | import android.view.MenuItem; 14 | import android.webkit.WebView; 15 | import android.webkit.WebViewClient; 16 | 17 | import androidx.appcompat.app.AppCompatActivity; 18 | 19 | import mobile.Mobile; 20 | 21 | /* 22 | * Displays the help message for Ivy. 23 | */ 24 | public class Help extends AppCompatActivity { 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_help); 30 | WebView webView = (WebView) findViewById(R.id.help_webview); 31 | webView.setWebViewClient(new WebViewClient() { 32 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 33 | // we are not a browser; redirect the request to proper apps. 34 | if (url != null) { 35 | view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); 36 | } 37 | return true; 38 | } 39 | }); 40 | webView.getSettings().setDefaultTextEncodingName("utf-8"); 41 | // mobile.Mobile was generated using gomobile bind robpike.io/ivy/mobile. 42 | String helpMsg = Mobile.help(); 43 | 44 | // loadData has a rendering bug: https://code.google.com/p/android/issues/detail?id=6965 45 | webView.loadDataWithBaseURL("http://pkg.go.dev/robpike.io/ivy", helpMsg, "text/html", "UTF-8", null); 46 | webView.setBackgroundColor(getResources().getColor(R.color.body)); 47 | } 48 | 49 | @Override 50 | public boolean onOptionsItemSelected(MenuItem item) { 51 | onBackPressed(); // back to parent. 52 | return true; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/drawable-hdpi/actionbar_solid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/res/drawable-hdpi/actionbar_solid.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/drawable-hdpi/ic_done_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/res/drawable-hdpi/ic_done_white_24dp.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/drawable-mdpi/actionbar_solid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/res/drawable-mdpi/actionbar_solid.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/drawable-mdpi/ic_done_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/res/drawable-mdpi/ic_done_white_24dp.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/drawable-xhdpi/actionbar_solid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/res/drawable-xhdpi/actionbar_solid.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/drawable-xhdpi/ic_done_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/res/drawable-xhdpi/ic_done_white_24dp.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/drawable-xxhdpi/actionbar_solid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/res/drawable-xxhdpi/actionbar_solid.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/drawable-xxhdpi/ic_done_white_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/res/drawable-xxhdpi/ic_done_white_24dp.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/drawable/circle_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/drawable/ivyabout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/res/drawable/ivyabout.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/layout/activity_about.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 15 | 22 | 23 | 29 | 30 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/layout/activity_help.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/menu/menu_about.xml: -------------------------------------------------------------------------------- 1 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 11 | 15 | 19 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/values-w820dp/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | OK 4 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #ffffeb 6 | #e2f6ff 7 | #1997d4 8 | #f9f9f9 9 | #000000 10 | 11 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Ivy 3 | 4 | Hello world! 5 | Settings 6 | Help 7 | About 8 | Clear 9 | Demo 10 | 11 | 12 | by Go Authors 13 | About Ivy 14 | Help 15 | ivy_sketch 16 | type an expression 17 | ivy sketch 18 | OK 19 | 20 | 21 | ceil 22 | floor 23 | rho 24 | abs 25 | iota 26 | sgn 27 | rev 28 | flip 29 | up 30 | down 31 | div 32 | idiv 33 | max 34 | min 35 | rho 36 | take 37 | drop 38 | mod 39 | imod 40 | or 41 | and 42 | nor 43 | nand 44 | xor 45 | def 46 | ) format 47 | ) op 48 | ) base 49 | ) origin 50 | 51 | 52 | -------------------------------------------------------------------------------- /example/ivy/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 | 16 | 17 | -------------------------------------------------------------------------------- /example/ivy/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | mavenCentral() 6 | google() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:7.0.3' 10 | } 11 | } 12 | 13 | allprojects { 14 | repositories { 15 | mavenCentral() 16 | google() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /example/ivy/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /example/ivy/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This is an empty package. 6 | // We have this package to convince this is buildable and go mod tidy can work. 7 | package dummy 8 | -------------------------------------------------------------------------------- /example/ivy/go.mod: -------------------------------------------------------------------------------- 1 | module golang.org/x/mobile/example/ivy 2 | 3 | go 1.23.0 4 | 5 | require ( 6 | golang.org/x/mobile v0.0.0-20210924032853-1c027f395ef7 7 | robpike.io/ivy v0.2.7 8 | ) 9 | 10 | require ( 11 | golang.org/x/mod v0.4.2 // indirect 12 | golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect 13 | golang.org/x/tools v0.1.2 // indirect 14 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect 15 | ) 16 | -------------------------------------------------------------------------------- /example/ivy/ios/README.md: -------------------------------------------------------------------------------- 1 | # Ivy iOS App source 2 | 3 | This directory contains the source code to the Ivy iOS app. 4 | 5 | To build, first create the Mobile.xcframework out of the Go 6 | implementation of Ivy. Run: 7 | 8 | ``` 9 | go install golang.org/x/mobile/cmd/gomobile@latest 10 | go install golang.org/x/mobile/cmd/gobind@latest 11 | ``` 12 | 13 | to install `gomobile` and `gobind`. Then: 14 | 15 | ``` 16 | mkdir work; cd work 17 | go mod init work 18 | go get -d golang.org/x/mobile/bind@latest 19 | go get -d robpike.io/ivy/mobile 20 | gomobile bind -target=ios,iossimulator,maccatalyst,macos robpike.io/ivy/mobile robpike.io/ivy/demo 21 | ``` 22 | 23 | Place the Mobile.xcframework directory in this directory, and 24 | then open ivy.xcodeproj in Xcode. 25 | 26 | You have to specify Development Team for code signing certificate in: 27 | Project Settings -> Targets -> Signing & Capabilities -> Signing -> Team. 28 | -------------------------------------------------------------------------------- /example/ivy/ios/ivy/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #import 6 | #import "IvyController.h" 7 | #import "Suggestion.h" 8 | 9 | @interface AppDelegate : UIResponder 10 | 11 | @property(strong, nonatomic) UIWindow *window; 12 | 13 | @end 14 | 15 | -------------------------------------------------------------------------------- /example/ivy/ios/ivy/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #import "AppDelegate.h" 6 | #import "IvyController.h" 7 | 8 | @interface AppDelegate () 9 | 10 | @end 11 | 12 | @implementation AppDelegate 13 | 14 | - (BOOL)application:(UIApplication *)application 15 | didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application { 20 | } 21 | 22 | - (void)applicationDidEnterBackground:(UIApplication *)application { 23 | } 24 | 25 | - (void)applicationWillEnterForeground:(UIApplication *)application { 26 | } 27 | 28 | - (void)applicationDidBecomeActive:(UIApplication *)application { 29 | } 30 | 31 | - (void)applicationWillTerminate:(UIApplication *)application { 32 | } 33 | 34 | @end 35 | 36 | -------------------------------------------------------------------------------- /example/ivy/ios/ivy/DocsController.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #import 6 | 7 | // DocsController displays the documentation page. 8 | @interface DocsController : UIViewController 9 | 10 | @end 11 | 12 | -------------------------------------------------------------------------------- /example/ivy/ios/ivy/DocsController.m: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #import "DocsController.h" 6 | #import "mobile/Mobile.h" 7 | 8 | @interface DocsController () { 9 | WKWebView *webView; 10 | } 11 | 12 | @end 13 | 14 | @implementation DocsController 15 | 16 | - (void)viewDidLoad { 17 | [super viewDidLoad]; 18 | webView = (WKWebView *)[self.view viewWithTag:11]; 19 | NSString *helpHTML = MobileHelp(); 20 | NSRange r = [helpHTML rangeOfString:@""]; 21 | NSString *html = [helpHTML substringToIndex:r.location]; 22 | 23 | // With the following meta tag, WKWebView displays the fonts more nicely. 24 | NSString *meta = @""; 29 | 30 | html = [html stringByAppendingString:@""]; 31 | html = [html stringByAppendingString:meta]; 32 | html = [html stringByAppendingString:[helpHTML substringFromIndex:r.location]]; 33 | 34 | [webView loadHTMLString:html baseURL:NULL]; 35 | } 36 | 37 | - (void)didReceiveMemoryWarning { 38 | [super didReceiveMemoryWarning]; 39 | } 40 | 41 | @end 42 | 43 | -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-100.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-1024.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-120.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-128.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-152.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-16.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-167.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-167.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-172.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-172.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-180.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-196.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-196.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-20.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-216.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-216.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-256.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-29.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-32.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-40.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-48.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-512.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-55.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-55.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-58.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-58.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-60.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-64.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-76.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-80.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-87.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-87.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-88.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/example/ivy/ios/ivy/Images.xcassets/AppIcon.appiconset/icon-88.png -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UIUserInterfaceStyle 6 | Light 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleDisplayName 10 | Ivy 11 | CFBundleExecutable 12 | $(EXECUTABLE_NAME) 13 | CFBundleIdentifier 14 | com.google.$(PRODUCT_NAME:rfc1034identifier) 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | $(PRODUCT_NAME) 19 | CFBundlePackageType 20 | APPL 21 | CFBundleShortVersionString 22 | 1.0 23 | CFBundleSignature 24 | ???? 25 | CFBundleVersion 26 | 6 27 | LSRequiresIPhoneOS 28 | 29 | UILaunchStoryboardName 30 | Launch 31 | UIMainStoryboardFile 32 | Main 33 | UIRequiredDeviceCapabilities 34 | 35 | UIRequiresFullScreen 36 | 37 | UISupportedInterfaceOrientations 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | UISupportedInterfaceOrientations~ipad 45 | 46 | UIInterfaceOrientationPortrait 47 | UIInterfaceOrientationPortraitUpsideDown 48 | UIInterfaceOrientationLandscapeLeft 49 | UIInterfaceOrientationLandscapeRight 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /example/ivy/ios/ivy/IvyController.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #import 6 | #import 7 | #import "Suggestion.h" 8 | 9 | // IvyController displays the main app view. 10 | @interface IvyController : UIViewController 11 | 12 | @property(weak, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint; 13 | 14 | // A text input field coupled to an output "tape", rendered with a WKWebView. 15 | @property(weak, nonatomic) IBOutlet UITextField *input; 16 | @property(strong, nonatomic) Suggestion *suggestionView; 17 | @property(weak, nonatomic) IBOutlet WKWebView *tape; 18 | @property(weak, nonatomic) IBOutlet UIButton *okButton; 19 | 20 | - (IBAction)clear:(id)sender; 21 | - (IBAction)demo:(id)sender; 22 | - (IBAction)okPressed:(id)sender; 23 | 24 | @end 25 | 26 | -------------------------------------------------------------------------------- /example/ivy/ios/ivy/Suggestion.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #import 6 | 7 | @protocol SuggestionDelegate 8 | 9 | @required 10 | - (void)suggestionReplace:(NSString *)text; 11 | @end 12 | 13 | @interface Suggestion : UIInputView 14 | 15 | - (instancetype)init; 16 | - (instancetype)initWithFrame:(CGRect)frame; 17 | - (void)suggestFor:(NSString *)text; 18 | 19 | @property(weak) id delegate; 20 | 21 | @end 22 | 23 | -------------------------------------------------------------------------------- /example/ivy/ios/ivy/en.lproj/Main.strings: -------------------------------------------------------------------------------- 1 | 2 | /* Class = "UITextField"; placeholder = "Type an expression"; ObjectID = "9SS-TP-C7c"; */ 3 | "9SS-TP-C7c.placeholder" = "Type an expression"; 4 | 5 | /* Class = "UIViewController"; title = "Ivy Controller"; ObjectID = "BYZ-38-t0r"; */ 6 | "BYZ-38-t0r.title" = "Ivy Controller"; 7 | 8 | /* Class = "UIBarButtonItem"; title = "Help"; ObjectID = "GSn-BW-al6"; */ 9 | "GSn-BW-al6.title" = "Help"; 10 | 11 | /* Class = "UINavigationItem"; title = "Ivy"; ObjectID = "KhW-J4-UcU"; */ 12 | "KhW-J4-UcU.title" = "Ivy"; 13 | 14 | /* Class = "UINavigationItem"; title = "Documentation"; ObjectID = "lf7-H3-aZF"; */ 15 | "lf7-H3-aZF.title" = "Documentation"; 16 | 17 | /* Class = "UIViewController"; title = "Docs"; ObjectID = "rfr-rm-AXI"; */ 18 | "rfr-rm-AXI.title" = "Docs"; 19 | -------------------------------------------------------------------------------- /example/ivy/ios/ivy/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import "AppDelegate.h" 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | @autoreleasepool 7 | { 8 | return UIApplicationMain(argc, argv, nil, 9 | NSStringFromClass([AppDelegate class])); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /example/ivy/ios/ivy/tape.html: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 34 | 35 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /example/ivy/tools.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build tools 6 | 7 | package dummy 8 | 9 | // This is a dummy go file to add required module dependencies to go.mod. 10 | 11 | import ( 12 | _ "golang.org/x/mobile/bind" 13 | _ "robpike.io/ivy" 14 | ) 15 | -------------------------------------------------------------------------------- /example/network/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 13 | 17 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /example/network/main_x.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !darwin && !linux && !windows 6 | 7 | package main 8 | 9 | func main() { 10 | } 11 | -------------------------------------------------------------------------------- /exp/README: -------------------------------------------------------------------------------- 1 | golang.org/x/mobile/exp contains experimental packages for mobile app 2 | development. 3 | -------------------------------------------------------------------------------- /exp/audio/al/alc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build darwin || linux || windows 6 | 7 | package al 8 | 9 | import ( 10 | "errors" 11 | "sync" 12 | "unsafe" 13 | ) 14 | 15 | var ( 16 | mu sync.Mutex 17 | device unsafe.Pointer 18 | context unsafe.Pointer 19 | ) 20 | 21 | // DeviceError returns the last known error from the current device. 22 | func DeviceError() int32 { 23 | return alcGetError(device) 24 | } 25 | 26 | // TODO(jbd): Investigate the cases where multiple audio output 27 | // devices might be needed. 28 | 29 | // OpenDevice opens the default audio device. 30 | // Calls to OpenDevice are safe for concurrent use. 31 | func OpenDevice() error { 32 | mu.Lock() 33 | defer mu.Unlock() 34 | 35 | // already opened 36 | if device != nil { 37 | return nil 38 | } 39 | 40 | dev := alcOpenDevice("") 41 | if dev == nil { 42 | return errors.New("al: cannot open the default audio device") 43 | } 44 | ctx := alcCreateContext(dev, nil) 45 | if ctx == nil { 46 | alcCloseDevice(dev) 47 | return errors.New("al: cannot create a new context") 48 | } 49 | if !alcMakeContextCurrent(ctx) { 50 | alcCloseDevice(dev) 51 | return errors.New("al: cannot make context current") 52 | } 53 | device = dev 54 | context = ctx 55 | return nil 56 | } 57 | 58 | // CloseDevice closes the device and frees related resources. 59 | // Calls to CloseDevice are safe for concurrent use. 60 | func CloseDevice() { 61 | mu.Lock() 62 | defer mu.Unlock() 63 | 64 | if device == nil { 65 | return 66 | } 67 | 68 | alcCloseDevice(device) 69 | if context != nil { 70 | alcDestroyContext(context) 71 | } 72 | device = nil 73 | context = nil 74 | } 75 | -------------------------------------------------------------------------------- /exp/audio/al/alc_notandroid.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build darwin || (linux && !android) || windows 6 | 7 | package al 8 | 9 | /* 10 | #cgo darwin CFLAGS: -DGOOS_darwin 11 | #cgo linux CFLAGS: -DGOOS_linux 12 | #cgo windows CFLAGS: -DGOOS_windows 13 | #cgo darwin LDFLAGS: -framework OpenAL 14 | #cgo linux LDFLAGS: -lopenal 15 | #cgo windows LDFLAGS: -lOpenAL32 16 | 17 | #ifdef GOOS_darwin 18 | #include 19 | #include 20 | #endif 21 | 22 | #ifdef GOOS_linux 23 | #include 24 | #include 25 | #endif 26 | 27 | #ifdef GOOS_windows 28 | #include 29 | #include 30 | #include 31 | #endif 32 | */ 33 | import "C" 34 | import "unsafe" 35 | 36 | /* 37 | On Ubuntu 14.04 'Trusty', you may have to install these libraries: 38 | sudo apt-get install libopenal-dev 39 | */ 40 | 41 | func alcGetError(d unsafe.Pointer) int32 { 42 | dev := (*C.ALCdevice)(d) 43 | return int32(C.alcGetError(dev)) 44 | } 45 | 46 | func alcOpenDevice(name string) unsafe.Pointer { 47 | n := C.CString(name) 48 | defer C.free(unsafe.Pointer(n)) 49 | 50 | return (unsafe.Pointer)(C.alcOpenDevice((*C.ALCchar)(unsafe.Pointer(n)))) 51 | } 52 | 53 | func alcCloseDevice(d unsafe.Pointer) bool { 54 | dev := (*C.ALCdevice)(d) 55 | return C.alcCloseDevice(dev) == C.ALC_TRUE 56 | } 57 | 58 | func alcCreateContext(d unsafe.Pointer, attrs []int32) unsafe.Pointer { 59 | dev := (*C.ALCdevice)(d) 60 | return (unsafe.Pointer)(C.alcCreateContext(dev, nil)) 61 | } 62 | 63 | func alcMakeContextCurrent(c unsafe.Pointer) bool { 64 | ctx := (*C.ALCcontext)(c) 65 | return C.alcMakeContextCurrent(ctx) == C.ALC_TRUE 66 | } 67 | 68 | func alcDestroyContext(c unsafe.Pointer) { 69 | C.alcDestroyContext((*C.ALCcontext)(c)) 70 | } 71 | -------------------------------------------------------------------------------- /exp/f32/gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build ignore 6 | 7 | package main 8 | 9 | /* 10 | This program generates table.go. Invoke it as: 11 | go run gen.go -output table.go 12 | */ 13 | 14 | import ( 15 | "bytes" 16 | "flag" 17 | "fmt" 18 | "go/format" 19 | "log" 20 | "math" 21 | "os" 22 | ) 23 | 24 | // N is the number of entries in the sin look-up table. It must be a power of 2. 25 | const N = 4096 26 | 27 | var filename = flag.String("output", "table.go", "output file name") 28 | 29 | func main() { 30 | b := new(bytes.Buffer) 31 | fmt.Fprintf(b, "// Code generated by go run gen.go; DO NOT EDIT\n\npackage f32\n\n") 32 | fmt.Fprintf(b, "const sinTableLen = %d\n\n", N) 33 | fmt.Fprintf(b, "// sinTable[i] equals sin(i * π / sinTableLen).\n") 34 | fmt.Fprintf(b, "var sinTable = [sinTableLen]float32{\n") 35 | for i := 0; i < N; i++ { 36 | radians := float64(i) * (math.Pi / N) 37 | fmt.Fprintf(b, "%v,\n", float32(math.Sin(radians))) 38 | } 39 | fmt.Fprintf(b, "}\n") 40 | 41 | data, err := format.Source(b.Bytes()) 42 | if err != nil { 43 | log.Fatal(err) 44 | } 45 | if err := os.WriteFile(*filename, data, 0644); err != nil { 46 | log.Fatal(err) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /exp/f32/mat3.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package f32 6 | 7 | import "fmt" 8 | 9 | // A Mat3 is a 3x3 matrix of float32 values. 10 | // Elements are indexed first by row then column, i.e. m[row][column]. 11 | type Mat3 [3]Vec3 12 | 13 | func (m Mat3) String() string { 14 | return fmt.Sprintf(`Mat3[% 0.3f, % 0.3f, % 0.3f, 15 | % 0.3f, % 0.3f, % 0.3f, 16 | % 0.3f, % 0.3f, % 0.3f]`, 17 | m[0][0], m[0][1], m[0][2], 18 | m[1][0], m[1][1], m[1][2], 19 | m[2][0], m[2][1], m[2][2]) 20 | } 21 | 22 | func (m *Mat3) Identity() { 23 | *m = Mat3{ 24 | {1, 0, 0}, 25 | {0, 1, 0}, 26 | {0, 0, 1}, 27 | } 28 | } 29 | 30 | func (m *Mat3) Eq(n *Mat3, epsilon float32) bool { 31 | for i := range m { 32 | for j := range m[i] { 33 | diff := m[i][j] - n[i][j] 34 | if diff < -epsilon || +epsilon < diff { 35 | return false 36 | } 37 | } 38 | } 39 | return true 40 | } 41 | 42 | // Mul stores a × b in m. 43 | func (m *Mat3) Mul(a, b *Mat3) { 44 | // Store the result in local variables, in case m == a || m == b. 45 | m00 := a[0][0]*b[0][0] + a[0][1]*b[1][0] + a[0][2]*b[2][0] 46 | m01 := a[0][0]*b[0][1] + a[0][1]*b[1][1] + a[0][2]*b[2][1] 47 | m02 := a[0][0]*b[0][2] + a[0][1]*b[1][2] + a[0][2]*b[2][2] 48 | m10 := a[1][0]*b[0][0] + a[1][1]*b[1][0] + a[1][2]*b[2][0] 49 | m11 := a[1][0]*b[0][1] + a[1][1]*b[1][1] + a[1][2]*b[2][1] 50 | m12 := a[1][0]*b[0][2] + a[1][1]*b[1][2] + a[1][2]*b[2][2] 51 | m20 := a[2][0]*b[0][0] + a[2][1]*b[1][0] + a[2][2]*b[2][0] 52 | m21 := a[2][0]*b[0][1] + a[2][1]*b[1][1] + a[2][2]*b[2][1] 53 | m22 := a[2][0]*b[0][2] + a[2][1]*b[1][2] + a[2][2]*b[2][2] 54 | m[0][0] = m00 55 | m[0][1] = m01 56 | m[0][2] = m02 57 | m[1][0] = m10 58 | m[1][1] = m11 59 | m[1][2] = m12 60 | m[2][0] = m20 61 | m[2][1] = m21 62 | m[2][2] = m22 63 | } 64 | -------------------------------------------------------------------------------- /exp/f32/vec3.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package f32 6 | 7 | import "fmt" 8 | 9 | type Vec3 [3]float32 10 | 11 | func (v Vec3) String() string { 12 | return fmt.Sprintf("Vec3[% 0.3f, % 0.3f, % 0.3f]", v[0], v[1], v[2]) 13 | } 14 | 15 | func (v *Vec3) Normalize() { 16 | sq := v.Dot(v) 17 | inv := 1 / Sqrt(sq) 18 | v[0] *= inv 19 | v[1] *= inv 20 | v[2] *= inv 21 | } 22 | 23 | func (v *Vec3) Sub(v0, v1 *Vec3) { 24 | v[0] = v0[0] - v1[0] 25 | v[1] = v0[1] - v1[1] 26 | v[2] = v0[2] - v1[2] 27 | } 28 | 29 | func (v *Vec3) Add(v0, v1 *Vec3) { 30 | v[0] = v0[0] + v1[0] 31 | v[1] = v0[1] + v1[1] 32 | v[2] = v0[2] + v1[2] 33 | } 34 | 35 | func (v *Vec3) Mul(v0, v1 *Vec3) { 36 | v[0] = v0[0] * v1[0] 37 | v[1] = v0[1] * v1[1] 38 | v[2] = v0[2] * v1[2] 39 | } 40 | 41 | func (v *Vec3) Cross(v0, v1 *Vec3) { 42 | v[0] = v0[1]*v1[2] - v0[2]*v1[1] 43 | v[1] = v0[2]*v1[0] - v0[0]*v1[2] 44 | v[2] = v0[0]*v1[1] - v0[1]*v1[0] 45 | } 46 | 47 | func (v *Vec3) Dot(v1 *Vec3) float32 { 48 | return v[0]*v1[0] + v[1]*v1[1] + v[2]*v1[2] 49 | } 50 | -------------------------------------------------------------------------------- /exp/f32/vec4.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package f32 6 | 7 | import "fmt" 8 | 9 | type Vec4 [4]float32 10 | 11 | func (v Vec4) String() string { 12 | return fmt.Sprintf("Vec4[% 0.3f, % 0.3f, % 0.3f, % 0.3f]", v[0], v[1], v[2], v[3]) 13 | } 14 | 15 | func (v *Vec4) Normalize() { 16 | sq := v.Dot(v) 17 | inv := 1 / Sqrt(sq) 18 | v[0] *= inv 19 | v[1] *= inv 20 | v[2] *= inv 21 | v[3] *= inv 22 | } 23 | 24 | func (v *Vec4) Sub(v0, v1 *Vec4) { 25 | v[0] = v0[0] - v1[0] 26 | v[1] = v0[1] - v1[1] 27 | v[2] = v0[2] - v1[2] 28 | v[3] = v0[3] - v1[3] 29 | } 30 | 31 | func (v *Vec4) Add(v0, v1 *Vec4) { 32 | v[0] = v0[0] + v1[0] 33 | v[1] = v0[1] + v1[1] 34 | v[2] = v0[2] + v1[2] 35 | v[3] = v0[3] + v1[3] 36 | } 37 | 38 | func (v *Vec4) Mul(v0, v1 *Vec4) { 39 | v[0] = v0[0] * v1[0] 40 | v[1] = v0[1] * v1[1] 41 | v[2] = v0[2] * v1[2] 42 | v[3] = v0[3] * v1[3] 43 | } 44 | 45 | func (v *Vec4) Dot(v1 *Vec4) float32 { 46 | return v[0]*v1[0] + v[1]*v1[1] + v[2]*v1[2] + v[3]*v1[3] 47 | } 48 | -------------------------------------------------------------------------------- /exp/font/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package font provides platform independent access to system fonts. 6 | package font 7 | -------------------------------------------------------------------------------- /exp/font/font.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build linux || darwin 6 | 7 | package font 8 | 9 | // Default returns the default system font. 10 | // The font is encoded as a TTF. 11 | func Default() []byte { 12 | b, err := buildDefault() 13 | if err != nil { 14 | panic(err) 15 | } 16 | return b 17 | } 18 | 19 | // Monospace returns the default system fixed-pitch font. 20 | // The font is encoded as a TTF. 21 | func Monospace() []byte { 22 | b, err := buildMonospace() 23 | if err != nil { 24 | panic(err) 25 | } 26 | return b 27 | } 28 | -------------------------------------------------------------------------------- /exp/font/font_android.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package font 6 | 7 | import "os" 8 | 9 | func buildDefault() ([]byte, error) { 10 | return os.ReadFile("/system/fonts/DroidSans.ttf") 11 | } 12 | 13 | func buildMonospace() ([]byte, error) { 14 | return os.ReadFile("/system/fonts/DroidSansMono.ttf") 15 | } 16 | -------------------------------------------------------------------------------- /exp/font/font_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !android 6 | 7 | package font 8 | 9 | import "os" 10 | 11 | func buildDefault() ([]byte, error) { 12 | // Try Noto first, but fall back to Droid as the latter was deprecated 13 | noto, nerr := os.ReadFile("/usr/share/fonts/truetype/noto/NotoSans-Regular.ttf") 14 | if nerr != nil { 15 | if droid, err := os.ReadFile("/usr/share/fonts/truetype/droid/DroidSans.ttf"); err == nil { 16 | return droid, nil 17 | } 18 | } 19 | return noto, nerr 20 | } 21 | 22 | func buildMonospace() ([]byte, error) { 23 | // Try Noto first, but fall back to Droid as the latter was deprecated 24 | noto, nerr := os.ReadFile("/usr/share/fonts/truetype/noto/NotoMono-Regular.ttf") 25 | if nerr != nil { 26 | if droid, err := os.ReadFile("/usr/share/fonts/truetype/droid/DroidSansMono.ttf"); err == nil { 27 | return droid, nil 28 | } 29 | } 30 | return noto, nerr 31 | } 32 | -------------------------------------------------------------------------------- /exp/font/font_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build linux || darwin 6 | 7 | package font 8 | 9 | import ( 10 | "bytes" 11 | "fmt" 12 | "testing" 13 | ) 14 | 15 | func looksLikeATTF(b []byte) error { 16 | if len(b) < 256 { 17 | return fmt.Errorf("not a TTF: not enough data") 18 | } 19 | b = b[:256] 20 | 21 | // Look for the 4-byte magic header. See 22 | // http://www.microsoft.com/typography/otspec/otff.htm 23 | switch string(b[:4]) { 24 | case "\x00\x01\x00\x00", "ttcf": 25 | // No-op. 26 | default: 27 | return fmt.Errorf("not a TTF: missing magic header") 28 | } 29 | 30 | // Look for a glyf table. 31 | if i := bytes.Index(b, []byte("glyf")); i < 0 { 32 | return fmt.Errorf(`not a TTF: missing "glyf" table`) 33 | } else if i%0x10 != 0x0c { 34 | return fmt.Errorf(`not a TTF: invalid "glyf" offset 0x%02x`, i) 35 | } 36 | return nil 37 | } 38 | 39 | func TestLoadDefault(t *testing.T) { 40 | def, err := buildDefault() 41 | if err != nil { 42 | t.Skip("default font not found") 43 | } 44 | if err := looksLikeATTF(def); err != nil { 45 | t.Errorf("default font: %v", err) 46 | } 47 | } 48 | 49 | func TestLoadMonospace(t *testing.T) { 50 | mono, err := buildMonospace() 51 | if err != nil { 52 | t.Skip("mono font not found") 53 | } 54 | if err := looksLikeATTF(mono); err != nil { 55 | t.Errorf("monospace font: %v", err) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /exp/gl/glutil/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package glutil implements OpenGL utility functions. 6 | package glutil 7 | -------------------------------------------------------------------------------- /exp/sensor/darwin_armx.m: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build darwin && (arm || arm64) 6 | // +build darwin 7 | // +build arm arm64 8 | 9 | #import 10 | 11 | CMMotionManager* manager = nil; 12 | 13 | void GoIOS_createManager() { 14 | manager = [[CMMotionManager alloc] init]; 15 | } 16 | 17 | void GoIOS_startAccelerometer(float interval) { 18 | manager.accelerometerUpdateInterval = interval; 19 | [manager startAccelerometerUpdates]; 20 | } 21 | 22 | void GoIOS_stopAccelerometer() { 23 | [manager stopAccelerometerUpdates]; 24 | } 25 | 26 | void GoIOS_readAccelerometer(int64_t* timestamp, float* v) { 27 | CMAccelerometerData* data = manager.accelerometerData; 28 | *timestamp = (int64_t)(data.timestamp * 1000 * 1000); 29 | v[0] = data.acceleration.x; 30 | v[1] = data.acceleration.y; 31 | v[2] = data.acceleration.z; 32 | } 33 | 34 | void GoIOS_startGyro(float interval) { 35 | manager.gyroUpdateInterval = interval; 36 | [manager startGyroUpdates]; 37 | } 38 | 39 | void GoIOS_stopGyro() { 40 | [manager stopGyroUpdates]; 41 | } 42 | 43 | void GoIOS_readGyro(int64_t* timestamp, float* v) { 44 | CMGyroData* data = manager.gyroData; 45 | *timestamp = (int64_t)(data.timestamp * 1000 * 1000); 46 | v[0] = data.rotationRate.x; 47 | v[1] = data.rotationRate.y; 48 | v[2] = data.rotationRate.z; 49 | } 50 | 51 | void GoIOS_startMagneto(float interval) { 52 | manager.magnetometerUpdateInterval = interval; 53 | [manager startMagnetometerUpdates]; 54 | } 55 | 56 | void GoIOS_stopMagneto() { 57 | [manager stopMagnetometerUpdates]; 58 | } 59 | 60 | void GoIOS_readMagneto(int64_t* timestamp, float* v) { 61 | CMMagnetometerData* data = manager.magnetometerData; 62 | *timestamp = (int64_t)(data.timestamp * 1000 * 1000); 63 | v[0] = data.magneticField.x; 64 | v[1] = data.magneticField.y; 65 | v[2] = data.magneticField.z; 66 | } 67 | 68 | void GoIOS_destroyManager() { 69 | [manager release]; 70 | manager = nil; 71 | } 72 | -------------------------------------------------------------------------------- /exp/sensor/notmobile.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build (linux && !android) || (darwin && !arm && !arm64) || windows 6 | 7 | package sensor 8 | 9 | import ( 10 | "errors" 11 | "time" 12 | ) 13 | 14 | func enable(t Type, delay time.Duration) error { 15 | return errors.New("sensor: no sensors available") 16 | } 17 | 18 | func disable(t Type) error { 19 | return errors.New("sensor: no sensors available") 20 | } 21 | 22 | func destroy() error { 23 | return nil 24 | } 25 | -------------------------------------------------------------------------------- /exp/sprite/clock/clock.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package clock provides a clock and time functions for a sprite engine. 6 | package clock 7 | 8 | // A Time represents an instant in sprite time. 9 | // 10 | // The application using the sprite engine is responsible for 11 | // determining sprite time. 12 | // 13 | // Typically time 0 is when the app is initialized and time is 14 | // quantized at the intended frame rate. For example, an app may 15 | // record wall time when it is initialized 16 | // 17 | // var start = time.Now() 18 | // 19 | // and then compute the current instant in time for 60 FPS: 20 | // 21 | // now := clock.Time(time.Since(start) * 60 / time.Second) 22 | // 23 | // An application can pause or reset sprite time, but it must be aware 24 | // of any stateful sprite.Arranger instances that expect time to 25 | // continue. 26 | type Time int32 27 | -------------------------------------------------------------------------------- /exp/sprite/clock/tween_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package clock 6 | 7 | import "testing" 8 | 9 | func TestLinear(t *testing.T) { 10 | t0 := Time(0) 11 | t1 := Time(6 * 60) 12 | now := Time(3 * 60) 13 | 14 | if c := Linear(t0, t1, now); c != 0.5 { 15 | t.Errorf("c=%.2f, want 0.5", c) 16 | } 17 | } 18 | 19 | func TestCubicBezier(t *testing.T) { 20 | t0 := Time(0) 21 | t1 := Time(1e6) 22 | 23 | tests := []struct { 24 | x0, y0, x1, y1 float32 25 | x, y float32 26 | }{ 27 | {0.00, 0.1, 0.4, 1.00, 0.0, 0.00}, 28 | {0.00, 0.1, 0.4, 1.00, 0.1, 0.26}, 29 | {0.00, 0.1, 0.4, 1.00, 0.5, 0.79}, 30 | {0.00, 0.1, 0.4, 1.00, 0.9, 0.99}, 31 | {0.00, 0.1, 0.4, 1.00, 1.0, 1.00}, 32 | {0.36, 0.2, 0.3, 0.85, 0.0, 0.0}, 33 | {0.36, 0.2, 0.3, 0.85, 0.3059, 0.3952}, 34 | {0.36, 0.2, 0.3, 0.85, 0.4493, 0.6408}, 35 | {0.36, 0.2, 0.3, 0.85, 0.8116, 0.9410}, 36 | {0.00, 0.0, 1.0, 1.00, 0.1, 0.1}, 37 | {0.00, 0.0, 1.0, 1.00, 0.5, 0.5}, 38 | {0.00, 0.0, 1.0, 1.00, 0.9, 0.9}, 39 | {0.42, 0.0, 1.0, 1.00, 0.0, 0.0}, 40 | } 41 | 42 | for _, test := range tests { 43 | cb := CubicBezier(test.x0, test.y0, test.x1, test.y1) 44 | now := t0 + Time(float32(t1-t0)*test.x) 45 | y := cb(t0, t1, now) 46 | 47 | const epsilon = 0.01 48 | diff := y - test.y 49 | if diff < -epsilon || +epsilon < diff { 50 | t.Errorf("CubicBezier(%.2f,%.2f,%.2f,%.2f): for x=%.2f got y=%.2f, want %.2f", test.x0, test.y0, test.x1, test.y1, test.x, y, test.y) 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /gl/work_other.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build (!cgo || (!darwin && !linux && !openbsd)) && !windows 6 | 7 | package gl 8 | 9 | // This file contains stub implementations of what the other work*.go files 10 | // provide. These stubs don't do anything, other than compile (e.g. when cgo is 11 | // disabled). 12 | 13 | type context struct{} 14 | 15 | func (*context) enqueue(c call) uintptr { 16 | panic("unimplemented; GOOS/CGO combination not supported") 17 | } 18 | 19 | func (*context) cString(str string) (uintptr, func()) { 20 | panic("unimplemented; GOOS/CGO combination not supported") 21 | } 22 | 23 | func (*context) cStringPtr(str string) (uintptr, func()) { 24 | panic("unimplemented; GOOS/CGO combination not supported") 25 | } 26 | 27 | type context3 = context 28 | 29 | func NewContext() (Context, Worker) { 30 | panic("unimplemented; GOOS/CGO combination not supported") 31 | } 32 | 33 | func Version() string { 34 | panic("unimplemented; GOOS/CGO combination not supported") 35 | } 36 | -------------------------------------------------------------------------------- /gl/work_windows_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | 7 | // fixFloat is unnecessary for windows/386 8 | TEXT ·fixFloat(SB),NOSPLIT,$0-16 9 | RET 10 | -------------------------------------------------------------------------------- /gl/work_windows_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | 7 | TEXT ·fixFloat(SB),NOSPLIT,$0-32 8 | MOVQ x0+0(FP), X0 9 | MOVQ x1+8(FP), X1 10 | MOVQ x2+16(FP), X2 11 | MOVQ x3+24(FP), X3 12 | RET 13 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module golang.org/x/mobile 2 | 3 | go 1.23.0 4 | 5 | // The modern go/types type checker produces types.Alias 6 | // types for the explicit representation of type aliases. 7 | // (Initial opt-in support for it was added in Go 1.22, 8 | // and it became the default behavior in Go 1.23.) 9 | // 10 | // TODO(go.dev/issue/70698): Update the golang.org/x/mobile/bind 11 | // code generator for the new behavior and delete this temporary¹ 12 | // forced pre-1.23 go/types behavior. 13 | // 14 | // ¹ It's temporary because this godebug setting will be removed 15 | // in a future Go release. 16 | godebug gotypesalias=0 17 | 18 | require ( 19 | golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 20 | golang.org/x/image v0.27.0 21 | golang.org/x/mod v0.24.0 22 | golang.org/x/sync v0.14.0 23 | golang.org/x/tools v0.33.0 24 | ) 25 | 26 | require golang.org/x/sys v0.33.0 // indirect 27 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 2 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 3 | golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 h1:3AGKexOYqL+ztdWdkB1bDwXgPBuTS/S8A4WzuTvJ8Cg= 4 | golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63/go.mod h1:UH99kUObWAZkDnWqppdQe5ZhPYESUw8I0zVV1uWBR+0= 5 | golang.org/x/image v0.27.0 h1:C8gA4oWU/tKkdCfYT6T2u4faJu3MeNS5O8UPWlPF61w= 6 | golang.org/x/image v0.27.0/go.mod h1:xbdrClrAUway1MUTEZDq9mz/UpRwYAkFFNUslZtcB+g= 7 | golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= 8 | golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= 9 | golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ= 10 | golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= 11 | golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= 12 | golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= 13 | golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc= 14 | golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI= 15 | -------------------------------------------------------------------------------- /internal/binres/genarsc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build ignore 6 | 7 | // Genarsc generates stripped down version of android.jar resources used 8 | // for validation of manifest entries. 9 | // 10 | // Requires the selected Android SDK to support the MinSDK platform version. 11 | package main 12 | 13 | import ( 14 | "fmt" 15 | "log" 16 | "os" 17 | "strconv" 18 | 19 | "golang.org/x/mobile/internal/binres" 20 | ) 21 | 22 | const tmpl = `// Copyright 2016 The Go Authors. All rights reserved. 23 | // Use of this source code is governed by a BSD-style 24 | // license that can be found in the LICENSE file. 25 | 26 | // Code generated by genarsc.go. DO NOT EDIT. 27 | 28 | package binres 29 | 30 | var arsc = []byte(%s)` 31 | 32 | func main() { 33 | arsc, err := binres.PackResources() 34 | if err != nil { 35 | log.Fatal(err) 36 | } 37 | if err := os.WriteFile("arsc.go", []byte(fmt.Sprintf(tmpl, strconv.Quote(string(arsc)))), 0644); err != nil { 38 | log.Fatal(err) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /internal/binres/testdata/bootstrap-res/mipmap-xxxhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/internal/binres/testdata/bootstrap-res/mipmap-xxxhdpi/icon.png -------------------------------------------------------------------------------- /internal/binres/testdata/bootstrap.arsc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/internal/binres/testdata/bootstrap.arsc -------------------------------------------------------------------------------- /internal/binres/testdata/bootstrap.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/internal/binres/testdata/bootstrap.bin -------------------------------------------------------------------------------- /internal/binres/testdata/bootstrap.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 13 | 14 | 15 | 16 | 25 | 30 | 31 | 32 | here is some text 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /internal/binres/testdata/gen.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | 3 | # version of build-tools tests run against 4 | AAPT=${ANDROID_HOME:-${HOME}/Android/Sdk}/build-tools/32.0.0/aapt 5 | 6 | # minimum version of android api for resource identifiers supported 7 | APIJAR=${ANDROID_HOME:-${HOME}/Android/Sdk}/platforms/android-16/android.jar 8 | 9 | for f in *.xml; do 10 | RES="" 11 | if [ -d "${f:0:-4}-res" ]; then 12 | RES="-S ${f:0:-4}-res" 13 | fi 14 | cp "$f" AndroidManifest.xml 15 | "$AAPT" p -M AndroidManifest.xml $RES -I "$APIJAR" -F tmp.apk 16 | unzip -qq -o tmp.apk AndroidManifest.xml resources.arsc 17 | mv AndroidManifest.xml "${f:0:-3}bin" 18 | mv resources.arsc "${f:0:-3}arsc" 19 | rm tmp.apk 20 | done 21 | -------------------------------------------------------------------------------- /internal/importers/ast_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package importers 6 | 7 | import ( 8 | "go/parser" 9 | "go/token" 10 | "reflect" 11 | "testing" 12 | ) 13 | 14 | func TestAnalyzer(t *testing.T) { 15 | file := `package ast_test 16 | 17 | import "Prefix/some/pkg/Name" 18 | import "Prefix/some/pkg/Name2" 19 | 20 | const c = Name.Constant 21 | 22 | type T struct { 23 | Name.Type 24 | unexported Name.Type2 25 | } 26 | 27 | func f() { 28 | Name2.Func().Func().Func() 29 | } 30 | ` 31 | fset := token.NewFileSet() 32 | f, err := parser.ParseFile(fset, "ast_test.go", file, parser.AllErrors) 33 | if err != nil { 34 | t.Fatal(err) 35 | } 36 | refs, err := AnalyzeFile(f, "Prefix/") 37 | if err != nil { 38 | t.Fatal(err) 39 | } 40 | exps := []PkgRef{ 41 | {Pkg: "some/pkg/Name", Name: "Constant"}, 42 | {Pkg: "some/pkg/Name", Name: "Type"}, 43 | {Pkg: "some/pkg/Name2", Name: "Func"}, 44 | {Pkg: "some/pkg/Name", Name: "Type2"}, 45 | } 46 | if len(refs.Refs) != len(exps) { 47 | t.Fatalf("expected %d references; got %d", len(exps), len(refs.Refs)) 48 | } 49 | for i, exp := range exps { 50 | if got := refs.Refs[i]; exp != got { 51 | t.Errorf("expected ref %v; got %v", exp, got) 52 | } 53 | } 54 | if _, exists := refs.Names["Constant"]; !exists { 55 | t.Errorf("expected \"Constant\" in the names set") 56 | } 57 | if len(refs.Embedders) != 1 { 58 | t.Fatalf("expected 1 struct; got %d", len(refs.Embedders)) 59 | } 60 | s := refs.Embedders[0] 61 | exp := Struct{ 62 | Name: "T", 63 | Pkg: "ast_test", 64 | Refs: []PkgRef{{Pkg: "some/pkg/Name", Name: "Type"}}, 65 | } 66 | if !reflect.DeepEqual(exp, s) { 67 | t.Errorf("expected struct %v; got %v", exp, s) 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /internal/mobileinit/mobileinit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package mobileinit contains common initialization logic for mobile platforms 6 | // that is relevant to both all-Go apps and gobind-based apps. 7 | // 8 | // Long-term, some code in this package should consider moving into Go stdlib. 9 | package mobileinit 10 | 11 | import "C" 12 | -------------------------------------------------------------------------------- /internal/mobileinit/mobileinit_ios.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package mobileinit 6 | 7 | import ( 8 | "io" 9 | "log" 10 | "os" 11 | "unsafe" 12 | ) 13 | 14 | /* 15 | #include 16 | #include 17 | 18 | os_log_t create_os_log() { 19 | return os_log_create("org.golang.mobile", "os_log"); 20 | } 21 | 22 | void os_log_wrap(os_log_t log, const char *str) { 23 | os_log(log, "%s", str); 24 | } 25 | */ 26 | import "C" 27 | 28 | type osWriter struct { 29 | w C.os_log_t 30 | } 31 | 32 | func (o osWriter) Write(p []byte) (n int, err error) { 33 | cstr := C.CString(string(p)) 34 | C.os_log_wrap(o.w, cstr) 35 | C.free(unsafe.Pointer(cstr)) 36 | return len(p), nil 37 | } 38 | 39 | func init() { 40 | log.SetOutput(io.MultiWriter(os.Stderr, osWriter{C.create_os_log()})) 41 | } 42 | -------------------------------------------------------------------------------- /testdata/gophercolor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/testdata/gophercolor.png -------------------------------------------------------------------------------- /testdata/gopherswim.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/testdata/gopherswim.png -------------------------------------------------------------------------------- /testdata/testpattern-window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/testdata/testpattern-window.png -------------------------------------------------------------------------------- /testdata/testpattern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang/mobile/a1d90793fc63015513ae877a689ddcc0903750ae/testdata/testpattern.png --------------------------------------------------------------------------------