可以在应用程序中使用GO作为脚本引擎吗?

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

Can GO be used as a scripting engine within an application?

问题

可以在应用程序中将GO用作脚本语言吗?我找不到任何关于这个的信息:是否有一个动态链接库版本,可以从Windows应用程序中与一些标准方法(如Compile()Execute())和功能(如callbacksvariables sharing等)进行接口交互?

英文:

Can GO be used as a scripting language within an application ? I can't find any informations about this: is there a dynamic link library version which could be interfaced from a Windows application with some standard methods such as Compile(), Execute and features such as callbacks, variables sharing etc ?

答案1

得分: 11

这可能一开始听起来有点奇怪,但请跟着我来:我认为它是一个完美的脚本语言候选,因为它的编译时间非常快...听我说...

大多数脚本语言都是解释型的,因此它们不需要(或者在某些情况下甚至不提供)编译。然而,编译语言通常更安全,因为它们可以在编译时捕捉到某些错误,这比在运行时捕捉到语法错误要好。

使用Go语言,编译时间非常快,以至于运行Go代码的程序(例如Web服务器)可以在需要时按需编译代码,否则使用已编译的版本。

实际上,如果你查看Google App Engine并下载他们为Go提供的开发Web服务器(https://developers.google.com/appengine/),你会注意到他们的Web服务器正是这样做的。如果你按照他们的Hello World教程运行Go代码,你会注意到如果你对代码进行更改,你不需要重新编译Go代码以使更改生效。

英文:

This might sound strange at first but go with me on this: I think it would be a perfect candidate for a scripting language because it's compile time is so fast....hear me out...

Most scripting languages are interpreted, and so they do not require (or even provide in some cases) compilation. However compiled languages are safer in general because they can catch certain errors at compile time, which is better than, for example, catching a syntax error at runtime.

With Go, the compile time is so speedy that whatever program is running your Go code (e.g. a web server) could hypothetically compile the code on-demand if the code has changed, and otherwise use the compiled version.

Actually if you check out Google App Engine and download their dev web server for Go (https://developers.google.com/appengine/) you'll notice that their web server does exactly this. If you run through their Hello World tutorial for Go you'll notice that if you make changes to your code you won't need to recompile the Go code in order for the changes to take affect.

答案2

得分: 5

Go不是一种脚本语言。由于Go被设计用于快速编译,因此有一些尝试将其用作脚本语言的方法。例如,

英文:

Go is not a scripting language. Because Go is designed for fast compilation, there have been some attempts to use it as a scripting language. For example,

答案3

得分: 0

理论上来说(也许在某个我不知道的地方),Go可以用作脚本语言。只是要注意,这样做的意义和使用C作为脚本语言一样。

英文:

In theory (and perhaps somewhere out there w/o me knowing), Go can be used as a script language. Just note that it makes as much sense as using e.g. C as a scripting language.

答案4

得分: 0

不可以。Go代码不能在非Go应用程序中使用,除非Go负责启动整个应用程序。

英文:

No. Go code cannot be used within a non-Go application unless Go is responsible for starting up the whole app.

huangapple
  • 本文由 发表于 2012年6月1日 21:54:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/10851624.html
匿名

发表评论

匿名网友

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

确定