Anko is a scriptable interpreter written in Go.

(Picture licensed under CC BY-SA 3.0, photo by Ocdp)
package main
import (
"fmt"
"log"
"github.com/mattn/anko/env"
"github.com/mattn/anko/vm"
)
func main() {
e := env.NewEnv()
err := e.Define("println", fmt.Println)
if err != nil {
log.Fatalf("Define error: %v\n", err)
}
script := `
println("Hello World :)")
`
_, err = vm.Execute(e, nil, script)
if err != nil {
log.Fatalf("Execute error: %v\n", err)
}
// output: Hello World :)
}
More examples are located in the GoDoc:
https://godoc.org/github.com/mattn/anko/vm
go get github.com/mattn/anko
go install github.com/mattn/anko
./anko script.ank
// declare variables
x = 1
y = x + 1
// print using outside the script defined println function
println(x + y) // 3
// if else statement
if x < 1 || y < 1 {
println(x)
} else if x < 1 && y < 1 {
println(y)
} else {
println(x + y)
}
// slice
a = []interface{1, 2, 3}
println(a) // [1 2 3]
println(a[0]) // 1
// map
a = map[interface]interface{"x": 1}
println(a) // map[x:1]
a.b = 2
a["c"] = 3
println(a["b"]) // 2
println(a.c) // 3
// struct
a = make(struct {
A int64,
B float64
})
a.A = 4
a.B = 5.5
println(a.A) // 4
println(a.B) // 5.5
// function
func a (x) {
println(x + 1)
}
a(5) // 6
// defer runs a function call when the surrounding function returns,
// in last-in first-out order
func b () {
defer println("world")
defer println("hello")
println("start")
}
b() // start, hello, world
The master branch language and API may change at any time.
To mitigate breaking changes, please use tagged branches. New tagged branches will be created for breaking changes.
Yasuhiro Matsumoto (a.k.a mattn)
This project exists thanks to all the people who contribute. [Contribute].
Become a financial contributor and help us sustain our community. [Contribute]
Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]
Overall
Maintained
Code review
Go module
Latest release
Releases this year
802 followers · starred Oct 2017
9,065 followers · starred Oct 2016
199 followers · starred Apr 2018
562 followers · starred Apr 2014
Anko is a scriptable interpreter written in Go.

(Picture licensed under CC BY-SA 3.0, photo by Ocdp)
package main
import (
"fmt"
"log"
"github.com/mattn/anko/env"
"github.com/mattn/anko/vm"
)
func main() {
e := env.NewEnv()
err := e.Define("println", fmt.Println)
if err != nil {
log.Fatalf("Define error: %v\n", err)
}
script := `
println("Hello World :)")
`
_, err = vm.Execute(e, nil, script)
if err != nil {
log.Fatalf("Execute error: %v\n", err)
}
// output: Hello World :)
}
More examples are located in the GoDoc:
https://godoc.org/github.com/mattn/anko/vm
go get github.com/mattn/anko
go install github.com/mattn/anko
./anko script.ank
// declare variables
x = 1
y = x + 1
// print using outside the script defined println function
println(x + y) // 3
// if else statement
if x < 1 || y < 1 {
println(x)
} else if x < 1 && y < 1 {
println(y)
} else {
println(x + y)
}
// slice
a = []interface{1, 2, 3}
println(a) // [1 2 3]
println(a[0]) // 1
// map
a = map[interface]interface{"x": 1}
println(a) // map[x:1]
a.b = 2
a["c"] = 3
println(a["b"]) // 2
println(a.c) // 3
// struct
a = make(struct {
A int64,
B float64
})
a.A = 4
a.B = 5.5
println(a.A) // 4
println(a.B) // 5.5
// function
func a (x) {
println(x + 1)
}
a(5) // 6
// defer runs a function call when the surrounding function returns,
// in last-in first-out order
func b () {
defer println("world")
defer println("hello")
println("start")
}
b() // start, hello, world
The master branch language and API may change at any time.
To mitigate breaking changes, please use tagged branches. New tagged branches will be created for breaking changes.
Yasuhiro Matsumoto (a.k.a mattn)
This project exists thanks to all the people who contribute. [Contribute].
Become a financial contributor and help us sustain our community. [Contribute]
Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]
Overall
Maintained
Code review
Go module
Latest release
Releases this year
802 followers · starred Oct 2017
9,065 followers · starred Oct 2016
199 followers · starred Apr 2018
562 followers · starred Apr 2014