1
0

Тайлбар байхгүй

mattn 6f35288cf6 Merge pull request #360 from brutella/lets-stmt-position 9 сар өмнө
.github c128b568c6 Update FUNDING.yml 4 жил өмнө
_example 9f09d87ab4 Removed colortext 6 жил өмнө
ast b6e3f09f31 Added make struct 4 жил өмнө
cmd a13910fe07 Fix cmd 5 жил өмнө
core f3f964422e 0.1.5 *Breaking Changes* Changed channel let statement to = <- 4 жил өмнө
env b6e3f09f31 Added make struct 4 жил өмнө
misc 006f729984 Add repl on wasm 6 жил өмнө
packages 7498a51438 Add strconv.Atoi 2 жил өмнө
parser 62d3c4a2d7 Fix indentation 9 сар өмнө
vm b791e68180 Fix empty position of lets-statement 9 сар өмнө
.travis.yml b6e3f09f31 Added make struct 4 жил өмнө
LICENSE 2f0391ad9b Updated license 6 жил өмнө
README.md b6e3f09f31 Added make struct 4 жил өмнө
anko.go 224ea1a7fd Updated parser type_data_struct 4 жил өмнө
anko.png 40de0349c8 Add anko 10 жил өмнө
anko_test.go 7494f9b570 Added interactive comment test 5 жил өмнө
go.mod cd70ffa519 Add go.mod 4 жил өмнө

README.md

Anko

GoDoc Reference Build Status Financial Contributors on Open Collective Coverage Go Report Card

Anko is a scriptable interpreter written in Go.

(Picture licensed under CC BY-SA 3.0, photo by Ocdp)

Usage Example - Embedded

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

Usage Example - Command Line

Building

go get github.com/mattn/anko
go install github.com/mattn/anko

Running an Anko script file named script.ank

./anko script.ank

Anko Script Quick Start

// 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

Please note that the master branch is not stable

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.

Author

Yasuhiro Matsumoto (a.k.a mattn)

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]