英文:
Embed a scripting language inside Go
问题
在Go语言中嵌入一种语言是可能的吗?我需要它来创建我的应用程序内的插件。
英文:
Is it possible to embed a language inside Go? I need it to create plugins inside my application.
答案1
得分: 37
我在虚拟机和语言上找到了这个列表。
- Gelo - 可扩展、可嵌入的解释器
- GoForth - 一个简单的Forth解析器
- GoLightly - 一个灵活且轻量级的虚拟机,具有可运行时配置的指令集
- Golog - Go语言中的Prolog解释器
- Minima - 用Go实现的一种语言
- RubyGoLightly - TinyRb到Go的实验性移植
- forego - Forth虚拟机
- go-python - CPython C-API的Go绑定
- GoEmPHP - 该包用于将PHP嵌入到Go中
- goenv - 创建一个隔离的环境,在其中安装Go包、二进制文件,甚至是C库。与Python的virtualenv非常相似。
- golemon - Lemon解析器生成器的一个移植版本
- goll1e - 用于Go编程语言的LL(1)解析器生成器
- golua - LUA的Go封装
- golua-fork - GoLua的一个分支,适用于当前版本的Go
- gotcl - Go中的Tcl解释器
- ngaro - 一个ngaro虚拟机,用于运行retroForth镜像
- otto - 用Go原生编写的JavaScript解析器和解释器
- monkey - 在你的Go程序中嵌入Mozilla JavaScript引擎SpiderMonkey
- go-v8 - Go语言的V8 JavaScript引擎绑定
- gomruby - Go语言的mruby (mini Ruby)绑定
- LispEx - 一种扩展支持并发编程的Lisp方言,用Go编写
更新:
-
Tengo - 一个小型、动态、快速、安全的Go脚本语言(与Go具有相似的语法)
-
Elsa - 基于QuickJS的TypeScript和JavaScript,与创建qemu、ffmpeg、tcc的同一人
英文:
I found the list on Virtual Machines and Languages.
- Gelo - Extensible, embeddable interpreter
- GoForth - A simple Forth parser
- GoLightly - A flexible and lightweight virtual machine with runtime-configurable instruction set
- Golog - Prolog interpreter in Go
- Minima - A language implemented in Go.
- RubyGoLightly - An experimental port of TinyRb to Go
- forego - Forth virtual machine
- go-python - go bindings for CPython C-API
- GoEmPHP - This package is built for Embedding PHP into Go.
- goenv - Create an isolated environment where you install Go packages, binaries, or even C libraries. Very similar to virtualenv for Python.
- golemon - A port of the Lemon parser-generator
- goll1e - An LL(1) parser generator for the Go programming language.
- golua - Go wrapper for LUA's C API
- golua-fork - A fork of GoLua that works on current releases of Go
- gotcl - Tcl interpreter in Go
- ngaro - An ngaro virtual machine to run retroForth images
- otto - A JavaScript parser and interpreter written natively in Go
- monkey - Embed SpiderMonkey, the Mozilla JavaScript engine, in your Go program.
- go-v8 - V8 JavaScript engine bindings for Go
- gomruby - mruby (mini Ruby) bindings for Go
- LispEx - A dialect of Lisp extended to support for concurrent programming, written in Go.
Update:
答案2
得分: 11
goja - 在Go语言中实现的ECMAScript 5.1(+)。
英文:
goja - ECMAScript 5.1(+) implementation in Go.
答案3
得分: 6
首先,我会解释一下cgo。Go语言提供了将值导出到C语言的API。
例如,你可以将字符串导出为char*
,如下所示:
package main
/*
#include <stdio.h>
static void myputs(char* s) {
puts(s);
}
*/
import "C"
func main() {
s := "hello world"
C.myputs(C.CString(s))
}
因此,你需要编写函数来访问C库。但也有一些用于使用脚本语言的包。请参考:
https://github.com/mattn/go-mruby
https://github.com/mattn/go-v8
或者,如果你不想使用C语言,你可以使用原生的Go语言,比如otto
https://github.com/robertkrimen/otto
英文:
At the first, I'll explain cgo. Go provides API to export values into C language.
For example, you can export string as char*
like below.
package main
/*
#include <stdio.h>
static void myputs(char* s) {
puts(s);
}
*/
import "C"
func main() {
s := "hello world"
C.myputs(C.CString(s))
}
So you need to write functions to access C library. But there are some packages to use script languages. See:
https://github.com/mattn/go-mruby
https://github.com/mattn/go-v8
Or if you don't want to use C language. You can use native go language like otto
答案4
得分: 3
一个非常好用的但没有在上面提到的是gopher-lua
,它是一个Lua 5.1虚拟机:
L := lua.NewState()
defer L.Close()
_ = L.DoString(`print("hello")`);
_ = L.DoFile("hello.lua");
英文:
One that is very nice to use, but wasn't mention above: gopher-lua
, a Lua 5.1 VM:
L := lua.NewState()
defer L.Close()
_ = L.DoString(`print("hello")`);
_ = L.DoFile("hello.lua");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论