News for hackers. Stuff that matters.
Re:Go and Android by dottrap on Sunday March 30, 2014 @02:33AM (#7495429)
Is there a way to build your Go stuff as a real, embeddable library and then call into it from C (via the NDK)?

I think this would be a more natural way of doing it, and also be potentially more reusable on other platforms like iOS (which forbid launching processes).

I would be interested in writing a simple HTTP server for my app in Go, and be able to invoke it (start, stop, etc) through a simple C-API. Then I could write the rest of the GUI in the native platform language (Java for Android, Objective-C for iOS).

Re:Go and Android by RyanZAG on Sunday March 30, 2014 @03:34AM (#7495516)
I don't believe this would be possible as Go requires a runtime environment and garbage collection. If you called into a Go library through a function, you would need to manually set up the runtime environment and garbage collection before hand (and manage it).

I think you'd be happier just using sockets to communicate with your Go process. I've done something similar before and it works well.

Re:Go and Android by dottrap on Sunday March 30, 2014 @07:53AM (#7495915)
So many languages allow doing this. Lua and Tcl are famous for this, but many other languages/runtimes also can do this, Python, Ruby, Javascript, C#, Java. They have a formal C API you can call through and define some memory management policy you need to conform to to interact with the garbage collector. This is pretty common stuff, albeit that some languages are much harder to embed than others.

As I said, spawning processes and IPC isn't an option on all platforms.

Are you sure Go doesn't have this ability?

Re:Go and Android by icebraining on Sunday March 30, 2014 @08:15AM (#7495955)
You can call Go from C, but the process main entry point must still be Go's, since that's the only way to launch its runtime. So technically you could embed it, but then you wouldn't be able to do any allocations or running goroutines.