github.com/mattn/anko@v0.1.10/README.md (about) 1 # Anko 2 3 [](http://godoc.org/github.com/mattn/anko/vm) 4 [](https://travis-ci.org/mattn/anko) 5 [](https://opencollective.com/mattn-anko) [](https://codecov.io/gh/mattn/anko) 6 [](https://goreportcard.com/report/github.com/mattn/anko) 7 8 Anko is a scriptable interpreter written in Go. 9 10  11 12 (Picture licensed under CC BY-SA 3.0, photo by Ocdp) 13 14 15 ## Usage Example - Embedded 16 17 ```go 18 package main 19 20 import ( 21 "fmt" 22 "log" 23 24 "github.com/mattn/anko/env" 25 "github.com/mattn/anko/vm" 26 ) 27 28 func main() { 29 e := env.NewEnv() 30 31 err := e.Define("println", fmt.Println) 32 if err != nil { 33 log.Fatalf("Define error: %v\n", err) 34 } 35 36 script := ` 37 println("Hello World :)") 38 ` 39 40 _, err = vm.Execute(e, nil, script) 41 if err != nil { 42 log.Fatalf("Execute error: %v\n", err) 43 } 44 45 // output: Hello World :) 46 } 47 ``` 48 49 More examples are located in the GoDoc: 50 51 https://godoc.org/github.com/mattn/anko/vm 52 53 54 ## Usage Example - Command Line 55 56 ### Building 57 ``` 58 go get github.com/mattn/anko 59 go install github.com/mattn/anko 60 ``` 61 62 ### Running an Anko script file named script.ank 63 ``` 64 ./anko script.ank 65 ``` 66 67 ## Anko Script Quick Start 68 ``` 69 // declare variables 70 x = 1 71 y = x + 1 72 73 // print using outside the script defined println function 74 println(x + y) // 3 75 76 // if else statement 77 if x < 1 || y < 1 { 78 println(x) 79 } else if x < 1 && y < 1 { 80 println(y) 81 } else { 82 println(x + y) 83 } 84 85 // slice 86 a = []interface{1, 2, 3} 87 println(a) // [1 2 3] 88 println(a[0]) // 1 89 90 // map 91 a = map[interface]interface{"x": 1} 92 println(a) // map[x:1] 93 a.b = 2 94 a["c"] = 3 95 println(a["b"]) // 2 96 println(a.c) // 3 97 98 // struct 99 a = make(struct { 100 A int64, 101 B float64 102 }) 103 a.A = 4 104 a.B = 5.5 105 println(a.A) // 4 106 println(a.B) // 5.5 107 108 // function 109 func a (x) { 110 println(x + 1) 111 } 112 a(5) // 6 113 ``` 114 115 116 ## Please note that the master branch is not stable 117 118 The master branch language and API may change at any time. 119 120 To mitigate breaking changes, please use tagged branches. New tagged branches will be created for breaking changes. 121 122 123 ## Author 124 125 Yasuhiro Matsumoto (a.k.a mattn) 126 127 ## Contributors 128 129 ### Code Contributors 130 131 This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. 132 <a href="https://github.com/mattn/anko/graphs/contributors"><img src="https://opencollective.com/mattn-anko/contributors.svg?width=890&button=false" /></a> 133 134 ### Financial Contributors 135 136 Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/mattn-anko/contribute)] 137 138 #### Individuals 139 140 <a href="https://opencollective.com/mattn-anko"><img src="https://opencollective.com/mattn-anko/individuals.svg?width=890"></a> 141 142 #### Organizations 143 144 Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/mattn-anko/contribute)] 145 146 <a href="https://opencollective.com/mattn-anko/organization/0/website"><img src="https://opencollective.com/mattn-anko/organization/0/avatar.svg"></a> 147 <a href="https://opencollective.com/mattn-anko/organization/1/website"><img src="https://opencollective.com/mattn-anko/organization/1/avatar.svg"></a> 148 <a href="https://opencollective.com/mattn-anko/organization/2/website"><img src="https://opencollective.com/mattn-anko/organization/2/avatar.svg"></a> 149 <a href="https://opencollective.com/mattn-anko/organization/3/website"><img src="https://opencollective.com/mattn-anko/organization/3/avatar.svg"></a> 150 <a href="https://opencollective.com/mattn-anko/organization/4/website"><img src="https://opencollective.com/mattn-anko/organization/4/avatar.svg"></a> 151 <a href="https://opencollective.com/mattn-anko/organization/5/website"><img src="https://opencollective.com/mattn-anko/organization/5/avatar.svg"></a> 152 <a href="https://opencollective.com/mattn-anko/organization/6/website"><img src="https://opencollective.com/mattn-anko/organization/6/avatar.svg"></a> 153 <a href="https://opencollective.com/mattn-anko/organization/7/website"><img src="https://opencollective.com/mattn-anko/organization/7/avatar.svg"></a> 154 <a href="https://opencollective.com/mattn-anko/organization/8/website"><img src="https://opencollective.com/mattn-anko/organization/8/avatar.svg"></a> 155 <a href="https://opencollective.com/mattn-anko/organization/9/website"><img src="https://opencollective.com/mattn-anko/organization/9/avatar.svg"></a>