V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
freestyle

wow skylark go 实现的 Python 语法的配置语言

  •  
  •   freestyle ·
    hanjm · Oct 4, 2017 · 1757 views
    This topic created in 3139 days ago, the information mentioned may be changed or developed.

    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"
    
    3 replies    2017-10-06 10:15:49 +08:00
    freestyle
        1
    freestyle  
    OP
       Oct 4, 2017
    fix output:
    ```
    hello world
    [0, 2, 4, 6, 8]
    *skylark.List [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    ```
    naomhan
        2
    naomhan  
       Oct 4, 2017
    Skylark in Go is an interpreter for Skylark, implemented in Go.

    Skylark is a dialect of Python intended for use as a configuration language.
    janxin
        3
    janxin  
       Oct 6, 2017
    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.

    这个可以做内嵌脚本系统用了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5886 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 131ms · UTC 03:18 · PVG 11:18 · LAX 20:18 · JFK 23:18
    ♥ Do have faith in what you're doing.