Embed a scripting language inside Go
3 answers
First, I will explain cgo. Go provides an API for exporting values ββto the C language.
For example, you can export a string char*
as shown 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 the C library. But there are several packages for using script languages. Cm:
https://github.com/mattn/go-mruby
https://github.com/mattn/go-v8
Or, if you do not want to use the C language, you can use the native language, for example otto
+4
source to share
Yes, I found the list here: https://github.com/golang/go/wiki/Projects#virtual-machines-and-languages
- Gelo - Extensible, embeddable interpreter
- GoForth - a simple Forth parser
- GoLightly - flexible and lightweight virtual machine with set command set times
- Golog - a Prolog interpreter in Go
- Minima is a language implemented in Go.
- RubyGoLightly - experimental port of TinyRb to Go
- forego - First virtual machine
- go-python - switch to CPython C-API binding
- GoEmPHP - This package is built to embed PHP in Go.
- goenv - Create a sandbox where you install Go packages, binaries, or even C libraries. Much like virtualenv for Python.
- golemon - port of the Lemon parser
- goll1e - LL (1) pair generator for the Go programming language.
- golua - Go to wrapper for LUA C API
- golua-fork - A GoLua fork that works with current versions of Go
- gotcl - Tcl interpreter in Go
- meme - a schema interpreter in Go
- ngaro - ngaro virtual machine for launching retro photographic images
- otto - JavaScript parser and interpreter originally written in Go
- monkey - Embed SpiderMonkey, the Mozilla JavaScript engine, into 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 parallel programming written in Go.
+17
source to share