AviatorScript Documentation

repository·master·Indexed 26 days ago

https://github.com/killme2008/aviatorscript

A high-performance, lightweight scripting language for the JVM and Android, designed for rule engines, formula calculations, and dynamic script control. It features ASM mode for JVM bytecode compilation, interpreter mode for non-standard platforms, and built-in support for bigint and decimal types. AviatorScript provides Java integration, a secure sandbox configuration, and a CLI for executing scripts via the com.googlecode.aviator.Main class.

Tokens
1.4K
Snippets
3
Records
9
Agent score
90%

What's inside AviatorScript

  1. Overview of AviatorScript

    master

    AviatorScript is a high-performance, lightweight scripting language that runs on the JVM (including Android). It supports basic types (numbers, strings, regex, booleans), functions as first-class citizens, closures, and functional programming.

    Key features include:

    • High Precision: Built-in bigint and decimal types with operator overloading.
    • Java Integration: Easy calling of Java methods and full support for Java Script API.
    • Execution Modes:
      • ASM Mode: Compiles scripts directly into JVM bytecode for high performance.
      • Interpreter Mode: Runs on non-standard Java platforms like Android.
    • Advanced Capabilities: Supports module systems, sequence abstraction for collections, serialization of compiled results for caching, and execution timeout settings to prevent resource exhaustion.
    • Security: Can be configured as a secure language sandbox.
  2. Quickstart: Install and run AviatorScript via CLI

    master

    You can use the aviator shell to run scripts from your terminal.

    1. Download the shell script and make it executable:
    $ wget https://raw.githubusercontent.com/killme2008/aviator/master/bin/aviator
    $ chmod u+x aviator
    1. Run the aviator command. This will automatically download the latest JAR to ~/.aviatorscript and launch the CLI:
    $ aviator
    1. Execute a script file:
    $ aviator hello.av

    CLI Usage Options:

    • java com.googlecode.aviator.Main [file] [args]: Run a script file with arguments.
    • java com.googlecode.aviator.Main -e [script]: Execute a raw script string.
    • java com.googlecode.aviator.Main -v: Version check.
    $ wget https://raw.githubusercontent.com/killme2008/aviator/master/bin/aviator
    $ chmod u+x aviator
    $ aviator
  3. Add AviatorScript dependency to Maven

    master

    To use AviatorScript in your Java project, add the following dependency to your pom.xml. It is recommended to use version 5.2.6 or higher.

    <dependency>
      <groupId>com.googlecode.aviator</groupId>
      <artifactId>aviator</artifactId>
      <version>{version}</version>
    </dependency>
  4. Upgrade the Aviator CLI

    master

    To upgrade the aviator script itself, use the upgrade command. This is intended for stable releases and should not be run from a git checkout. You can specify a target version (like a branch name or tag) as the second argument.

    Note: If you are using a SNAPSHOT build, the upgrade task is disabled.

  5. Example AviatorScript syntax

    master

    Below is an example of AviatorScript syntax demonstrating printing, collection processing with reduce, and Java interoperability:

    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)}");
  6. Configure Aviator environment variables

    master

    You can customize the Aviator installation and runtime behavior using the following environment variables:

    VariableDescription
    AVIATOR_HOMEThe root directory for Aviator. Defaults to $HOME/.aviatorscript.
    AVIATOR_DEPSDirectory containing dependency JARs. Defaults to $AVIATOR_HOME/deps.
    AVIATOR_JAVA_CMDThe command used to run Java. Defaults to java.
    AVIATOR_JVM_OPTSJVM options passed to the process. Inherits from $JAVA_OPTS if not set.
    HTTP_CLIENTThe command used to download the Aviator JAR. Defaults to wget -O or curl.
    DEBUGIf set, the CLI will print the constructed CLASSPATH to stdout.
  7. Troubleshoot SSL/Download issues

    master

    If the self-install process fails due to SSL certificate issues (common with older libssl versions), you can instruct the CLI to use an insecure HTTP client by setting the HTTP_CLIENT environment variable:

    # For wget
    export HTTP_CLIENT="wget --no-check-certificate -O"
    
    # For curl
    export HTTP_CLIENT="curl --insecure -f -L -o"
  8. Run AviatorScript via CLI

    master

    You can run AviatorScript scripts directly from the command line using the com.googlecode.aviator.Main class. The CLI supports executing script files, executing raw script strings, and checking the version.

    Usage Modes

    1. Execute a script file: Pass the path to the script file as the first argument. Any subsequent arguments are passed to the script as ARGV. java com.googlecode.aviator.Main [file] [args]

    2. Execute a script string: Use the -e or --execute flag followed by the script content. Subsequent arguments are passed as ARGV. java com.googlecode.aviator.Main -e [script] [args]

    3. Check version: Use the -v or --version flag. java com.googlecode.aviator.Main -v

    Script Environment Variables

    When running via CLI, the following variables are available in the script's environment:

    • ARGV: An array of arguments passed after the script/command.
    • __MODULE__: A module object containing:
      • exports: An object for exporting values.
      • path: The absolute path of the script.
      • dir: The directory containing the script.
  9. Use the Aviator CLI

    master
    The aviator executable is the primary entrypoint for running AviatorScript. It manages its own installation, dependencies, and JVM configuration. By default, it will attempt to perform a self-install if the required JAR is not found in your AVIATOR_HOME.