我可以写一个可以从其他语言使用的 Go 库吗?

huangapple go评论93阅读模式
英文:

Can I write go library to be used from another languages?

问题

我正在编写一个相对较小但不简单的网络库,至少要在C、Java、Python、Ruby和C#中使用。是否有办法像在C中那样创建与其他语言的绑定?如果没有,是否有其他方法?

英文:

I'm writing relatively small, but not simple networking library which is going to be used at least from C,java,python,ruby and C#. Is there a way to make go bindings to the other languages the way in can be done form C? If not is there other way?

答案1

得分: 3

目前,你无法使用Go编写可以在其他语言中使用的库。Go具有一个运行时环境,它可以为你执行许多操作(如调度go-routines、收集垃圾)。这个运行时环境是在假设它控制整个程序的前提下编写的。如果从另一种语言中使用Go代码,这个假设就不成立了,因为Go库无法影响使用它的二进制文件。

英文:

Right now, you can't write libraries in Go that can be used in other languages. Go has a runtime environment that does a lot of things (like sheduling go-routines, collecting garbage) for you. This runtime environment is written under the assumption that it controls the whole program. This assumption does not hold if Go code would be used from inside another language, as the Go library cannot influence the binary that uses it.

答案2

得分: 0

我想象一个JSON服务可以实现你描述的功能。可以参考这个JSON测试来了解一个简单的例子。无论你使用什么语言来设置和获取应用程序的数据都没有关系。

英文:

I imagine that a JSON service would do what you describe.
Have a look at the json test for a simple example
It wouldnt matter what languages you used to set and get data from your app

huangapple
  • 本文由 发表于 2014年5月20日 22:52:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/23763197.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定