Q Language : A script language for Go

Q Language - A script language for Go

LICENSE Build Status Go Report Card GitHub release GoDoc

Qiniu Logo

语言特色

  • 与 Go 语言有最好的互操作性。可不进行任何包装即可直接使用 Go 语言的函数、类及其成员变量和方法。
  • 有赖于 Go 语言的互操作性,这门语言直接拥有了一套非常完整且您十分熟悉的标准库,无额外学习成本。
  • 与 Go 十分相近的语法,降低您的学习成本。
  • 支持 Go 绝大部分语言特性,包括:for range, string, slice, map, chan, goroutine, defer, etc。
  • 微内核:语言的核心只有大约 1200 行代码。所有功能以可插拔的 module 方式提供。

预期的商业场景:

  • 由于与 Go 语言的无缝配合,qlang 在嵌入式脚本领域有 lua、python、javascript 所不能比拟的优越性。比如:网络游戏中取代 lua 的位置。
  • 作为编译原理的教学语言。由于 qlang 的 Compiler 代码极短,便于阅读和理解,非常方便教学实践之用。

快速入门

在您的 Go 代码中整合 qlang

import (
	"fmt"
	"log"
	"strings"

	"github.com/xushiwei/qlang"
	_ "github.com/xushiwei/qlang/lib/builtin" // 导入 builtin 包
)

var strings_Exports = map[string]interface{}{
	"replacer": strings.NewReplacer,
}

func main() {

	qlang.Import("strings",	strings_Exports) // 导入一个自定义的包,叫 strings(和标准库同名)
	ql := qlang.New()

	err := ql.SafeEval(`x = strings.replacer("?", "!").replace("hello, world???")`)
	if err != nil {
		log.Fatal(err)
		return
	}

	fmt.Println("x:", ql.Var("x")) // 输出 x: hello, world!!!
}

这是一个功能最精简功能的迷你版 qlang。

想要了解更多,可参考“定制 qlang”相关内容。实际项目中你也可以参考代码:

非嵌入式场景下使用 qlang

尽管我们认为 qlang 的优势领域是在与 Go 配合的嵌入式场景,但您也可以把 qlang 语言用于非嵌入式脚本领域。

您可以直接通过 qlang 命令行程序来执行 *.ql 的代码。如下:

qlang xxx.ql 
    
    
      ... 
     

     
    
   

为了方便学习 qlang 工作机理,我们支持导出 qlang 编译的 “汇编指令”:

QLANG_DUMPCODE=1 qlang xxx.ql 
    
    
      ... 
     

     
    
   

在 Unix 系的操作系统下,您可以在 xxx.ql 文件开头加上:

#!/usr/bin/env qlang

并给 xxx.ql 文件加上可执行权限,即可直接运行 xxx.ql 脚本。

使用 qlang shell

命令行下输入 qlang 命令(不带参数),直接进入 qlang shell。

您同样也可以设置 QLANG_DUMPCODE 环境变量来学习 qlang 的工作机理:

QLANG_DUMPCODE=1 qlang

学习 qlang 语言特性

  • Q 语言手册: 这里有语言特性的详细介绍。
  • Qlang Tutorials: 这里是一些 qlang 的样例代码,供您学习 qlang 时参考。

下载

发行版本

最新版本

go get github.com/xushiwei/qlang

社区资源

Embedded qlang (eql)

  • eql: 全称 embedded qlang,是类似 erubis/erb 的东西。结合 go generate 可很方便地让 Go 支持模板(不是 html template,是指泛型)。

为 Go package 导出 qlang module

  • qexport: 可为 Go 语言的标准库或者你自己写的 Go Package 自动导出相应的 qlang module。

Qlang Modules

IDE 插件

Similar Resources

Learning GO language by building projects

Learning GO language by building projects

GoLangProjects Projects list Helloworld Variables Userinput Conversion Math, crypto & random Time & Date Pointers Arrays Slices Maps Structures If-Els

Dec 5, 2022

Crud with Go Language!

CRUD With GO! CRUD with Go Language! How to use with Docker-Compose git clone this project open the cloned folder in the terminal and cd backend/ run

Oct 12, 2021

A practical journey into the Golang Programming Language

OneTutorial - A practical journey into the Golang Programming Language This little project will help you touch many topics around Golang, in a small a

Oct 21, 2021

slang 🐕‍🦺 | a Programing language written to understand how programing languages are written

slang 🐕‍🦺 goal was to learn how a interpreter works, in other works who does these programing languages i use on daily basis works behind the seen h

Nov 18, 2021

Tutorial and sample codes for Go language

Tutorial and sample codes for Go language

Jan 4, 2022

Learn the Go programming language (Golang) in this step-by-step tutorial course for beginners

Learn the Go programming language (Golang) in this step-by-step tutorial course for beginners. Go is an open source programming language designed at Google that makes it easy to build simple, reliable, and efficient software.

Dec 16, 2021

Programming language for the Orwell's Blockchain

orwells-language Programming language for the Orwell's Blockchain Keywords and notations var // Variable declaration if // Conditional decla

Dec 26, 2021

The go language version developed based on hashlips_art_engine. Added and deleted some functions

The go language version developed based on hashlips_art_engine. Added and deleted some functions

golips_art_engine The inspiration for this tool is based on HashLips Art Engine. Our official links 🐦 Twitter 💄 Discord 💄 NFT Why building a new to

Jul 28, 2022

Gentee - script programming language for automation. It uses VM and compiler written in Go (Golang).

Gentee script programming language Gentee is a free open source script programming language. The Gentee programming language is designed to create scr

Dec 15, 2022

A fast script language for Go

A fast script language for Go

The Tengo Language Tengo is a small, dynamic, fast, secure script language for Go. Tengo is fast and secure because it's compiled/executed as bytecode

Dec 30, 2022

Gentee - script programming language for automation. It uses VM and compiler written in Go (Golang).

Gentee script programming language Gentee is a free open source script programming language. The Gentee programming language is designed to create scr

Dec 15, 2022

A fast script language for Go

A fast script language for Go

The Tengo Language Tengo is a small, dynamic, fast, secure script language for Go. Tengo is fast and secure because it's compiled/executed as bytecode

Dec 30, 2022

The interpreter for qiitan script. Yet another dialect of the Tengo language.

Qiitan は、Qiita ™️ の SNS である「Qiitadonβ」のマスコット・キャラクターです。 キーたん(Qiitan) @ Qiitadon Qiitan-go は Qiitan のファン・アプリであり、Qiita ™️ とは一切関係がありません。 Qiitan-goalpha キー

Feb 6, 2022

xlsxlang is a tiny toy script programming language. xlsxlang is heavily inspired by Lisp

xlsxlang is a tiny toy script programming language. xlsxlang is heavily inspired by Lisp

xlsxlang Table of Contents 1. Usage 1.1. Examples 2. Installation 3. Supported functions 4. LICENSE xlsxlang is a tiny toy script programming language

Feb 11, 2022

Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development

Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development

Go bindings for Sciter Check this page for other language bindings (Delphi / D / Go / .NET / Python / Rust). Attention The ownership of project is tra

Dec 23, 2022

Shell script to download and set GO environmental paths to allow multiple versions.

Shell script to download and set GO environmental paths to allow multiple versions.

gobrew gobrew lets you easily switch between multiple versions of go. It is based on rbenv and pyenv. Installation The automatic installer You can ins

Nov 3, 2022

A simple Go script to brute force or parse a password-protected PKCS#12 (PFX/P12) file.

A simple Go script to brute force or parse a password-protected PKCS#12 (PFX/P12) file.

A simple Go script to brute force or parse a password-protected PKCS#12 (PFX/P12) file.

Oct 14, 2022

View the script files in the original Resident Evil 2 / Biohazard 2 as pseudocode

View the script files in the original Resident Evil 2 / Biohazard 2 as pseudocode

Resident Evil 2 Script Viewer About You can view the script files in the original Resident Evil 2 / Biohazard 2 as pseudocode next to the original byt

Jan 20, 2022

流媒体NetFlix解锁检测脚本 / A script used to determine whether your network can watch native Netflix movies or not

流媒体NetFlix解锁检测脚本 / A script used to determine whether your network can watch native Netflix movies or not

netflix-verify 流媒体NetFlix解锁检测脚本,使用Go语言编写 在VPS网络正常的情况下,哪怕是双栈网络也可在几秒内快速完成IPv4/IPv6的解锁判断 鸣谢 感谢 @CoiaPrant 指出对于地域检测更简便的方法 感谢 @XmJwit 解决了IPV6 Only VPS无法下载脚

Dec 29, 2022
A repository for showcasing my knowledge of the Google Go (2009) programming language, and continuing to learn the language.

Learning Google Golang (programming language) Not to be confused with the Go! programming language by Francis McCabe I don't know very much about the

Nov 6, 2022
A repository for showcasing my knowledge of the Go! (2003) programming language, and continuing to learn the language.
A repository for showcasing my knowledge of the Go! (2003) programming language, and continuing to learn the language.

Learning Go! (programming language) Not to be confused with Google Golang (2009) I don't know too much about the Go! programming language, but I know

Oct 22, 2022
Go programming language secure coding practices guide

You can download this book in the following formats: PDF, Mobi and ePub. Introduction Go Language - Web Application Secure Coding Practices is a guide

Jan 9, 2023
The Little Go Book is a free introduction to Google's Go programming language
The Little Go Book is a free introduction to Google's Go programming language

The Little Go Book is a free introduction to Google's Go programming language. It's aimed at developers who might not be quite comfortable with the idea of pointers and static typing. It's longer than the other Little books, but hopefully still captures that little feeling.

Jan 2, 2023
Some examples for the programming language Go.

Golang_Examples Bubblesort: simple implementation of bubble sort algorithm in Go Level: Beginner GenericStack: a stack (LIFO collection) that can hold

Jul 28, 2022
Crash Course about the programming language Go / Golang.
Crash Course about the programming language Go / Golang.

Crash Course about the programming language Go / Golang. In this course I have covered some important concepts and topics in programming.

Oct 10, 2022
Building a shoe store with golang to learn more about this language :)

shoestore-go Building a shoe store with golang to learn more about this language :) TODO Create a basic webpage with the pages: home : to show homepag

Jan 24, 2022
A complete guide to undersatnd golang programming language, web requests, JSON and creating web APIs with mongodb

Golang series A complete guide to undersatnd golang programming language, web requests, JSON and creating web APIs with mongodb LearnCodeonline.in 01

Jan 1, 2023
go programming language tutorial

go programming language tutorial Hello World Hello World fmt package Variables Short Declaration The Var Keyword Exploring Type Own Type Conversion Ty

Aug 27, 2022
An open source programming language that makes it easy to build simple
An open source programming language that makes it easy to build simple

The Go Programming Language Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. Gopher ima

Oct 15, 2021