📖 English Documentation | 📖 中文文档
AviatorScript
is a lightweight, high performance scripting language hosted on the JVM (and Android platform).
It compiles script to java byte code and evaluate it on the fly.
It's not a game, it's a programming language. Please refrain from sending me any more unsolicited emails.RTFM
- Supports basic types such as numbers, strings, regular expressions, booleans, and more. Full support for all Java operators and precedence, etc. Basic Types.
- Functions are first-class, supporting closures and functional programming.
- Built-in bigint/decimal types for large integers and high-precision calculations. Supports operator overloading to allow these types to use common arithmetic operators
+-*/
. - Full script syntax support, including multiline data, conditional statements, loop statements, lexical scoping, and exception handling.
- Functional programming combined with Sequence abstraction for convenient collection handling.
- Lightweight module system.
- Multiple ways to easily call Java methods, with full support for the Java script API (facilitating script calls from Java).
- Rich customization options, usable as a secure language sandbox and a fully featured language.
- Dynamic compilation and execution, lightweight, and high performance. In ASM mode, it directly compiles scripts into JVM bytecode. Interpretation mode can run on non-standard Java platforms like Android.
- Supports serialization of compiled results, facilitating caching and compiling acceleration. Supports execution timeout settings to prevent resource exhaustion by disruptive scripts.
Recommend version 5.2.6 and above.
- 5.4.3,add the
enableSandboxMode
to enable sandbox mode etc. - 5.4.2,add the
getFunctionNames
method to retrieve a list of functions and set the evaluation timeout, etc. - 5.4.1,Fixed recursive function can't work, fixed function can't be serialized etc.
<dependency>
<groupId>com.googlecode.aviator</groupId>
<artifactId>aviator</artifactId>
<version>{version}</version>
</dependency>
Check available versions at search.maven.org.
- Download aviator shell script to a directory in system
PATH
environment variable,such as~/bin/aviator
:
$ wget https://raw.githubusercontent.com/killme2008/aviator/master/bin/aviator
$ chmod u+x aviator
- Execute
aviator
command,it will download the latest aviator jar to~/.aviatorscript
directory:
$ aviator
Downloading AviatorScript now...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 153 100 153 0 0 111 0 0:00:01 0:00:01 --:--:-- 111
100 1373k 100 1373k 0 0 689k 0 0:00:01 0:00:01 --:--:-- 689k
Usage: java com.googlecode.aviator.Main [file] [args]
: java com.googlecode.aviator.Main -e [script]
: java com.googlecode.aviator.Main -v
- Save the script below in file
hello.av
:
p("Hello, AviatorScript!");
let a = tuple(1, 2, 3, 4, 5);
p("sum of a is: " + reduce(a, +, 0));
let date = new java.util.Date();
p("The year is: "+ getYear(date));
p("The month is: #{getMonth(date)}");
- Execute the script with
aviator
command:
$ aviator hello.av
Hello, AviatorScript!
sum of a is: 15
The year is: 120
The month is: 3
A complex example is calculator.av which evaluates arithmetic expression in string.
Read user guide for details.
- Releases: https://github.com/killme2008/aviator/releases
- Documents: https://www.yuque.com/boyan-avfmj/aviatorscript
- Changelog: https://www.yuque.com/boyan-avfmj/aviatorscript/bggwx2
- Javadoc: http://fnil.net/aviator/apidocs/
- Spring boot rule: https://github.com/mengxiangrui007/spring-boot-rule-jsr94
- Idea plugin: https://github.com/yanchangyou/aviatorscript-ideaplugin