https://github.com/google/skylark
package main
import (
"github.com/google/skylark"
"log"
"fmt"
)
func main() {
script := `print("hello {}".format("world"))
print([i for i in range(10) if i%2==0])`
thread := new(skylark.Thread)
globals := make(skylark.StringDict)
err := skylark.ExecFile(thread, "", script, globals)
if err != nil {
log.Fatalf("eval error:%s", err)
}
value, err := skylark.Eval(thread, "", "range(10)", globals)
if err != nil {
log.Fatalf("eval error:%s", err)
}
fmt.Printf("%T %v", value, value)
}
hello world
[0, 2, 4, 6, 8]
*skylark.List [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]skylark.String "hello world"
1
freestyle OP fix output:
``` hello world [0, 2, 4, 6, 8] *skylark.List [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ``` |
2
naomhan 2017-10-04 11:34:09 +08:00
Skylark in Go is an interpreter for Skylark, implemented in Go.
Skylark is a dialect of Python intended for use as a configuration language. |
3
janxin 2017-10-06 10:15:49 +08:00
Skylark is a dialect of Python intended for use as a configuration language. Like Python, it is an untyped dynamic language with high-level data types, first-class functions with lexical scope, and garbage collection. Unlike CPython, independent Skylark threads execute in parallel, so Skylark workloads scale well on parallel machines.
这个可以做内嵌脚本系统用了 |