Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed a scripting language inside Go

Is it possible to embed a language inside Go? I need it to create plugins inside my application.

like image 586
Kokizzu Avatar asked Dec 16 '14 03:12

Kokizzu


3 Answers

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
  • meme - Scheme 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:

  • Tengo - a small, dynamic, fast, secure script language for Go. (similar syntax with Go)
  • glua, GoLuaJit, gijit, and others - LuaJIT, one of fastest JIT implementation
  • Elsa - Typescript and Javascript, based on QuickJS, same person who creates qemu, ffmpeg, tcc
like image 188
Kokizzu Avatar answered Oct 05 '22 21:10

Kokizzu


goja - ECMAScript 5.1(+) implementation in Go.

like image 32
funny_falcon Avatar answered Oct 05 '22 21:10

funny_falcon


At the first, I'll explain cgo. Go provides API to export values into C language.

http://golang.org/cmd/cgo/

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

https://github.com/robertkrimen/otto

https://github.com/mattn/anko

like image 35
mattn Avatar answered Oct 05 '22 23:10

mattn