Skip to main content

Jactl

A secure, embeddable, open source scripting language for Java-based applications

Familiar Syntax

Subset of Java/Groovy syntax with a touch of Perl mixed in.

15:aload_016:getfield#219:iconst_120:iadd21:istore_1...28:iload_129:bipush1031:if_icmpge4534:getstatic#337:ldc#439:invokevirtual#5...

Compiles to Java Bytecode

Compiles to bytecode for fast execution times. Supports Java 8 (and later).

10101011001100110111100001011010110111001000101110101100100110011010110010100101100101101100

Secure

Scripts are tightly controlled. They can only perform operations allowed by the application in which Jactl is embedded.

Never Blocks

Built-in continuation mechanism allows scripts to suspend execution while waiting for asynchronous responses and then resume from where they left off. Execution thread is never blocked while waiting for a long-running response.

Execution State Checkpointing

Execution state can be checkpointed and persisted or distributed over a network to allow scripts to be recovered and resumed from where they left off after a failure.

No Dependencies

Jactl does not have any dependencies on any other libraries (apart from an embedded instance of the stand-alone ASM library).

Hello World

Simple program to print "Hello World!".

println 'Hello World!'

String Expressions

Strings with double quotes allow embedded references to variables using $ or to arbitrary expressions using ${...}. Triple single quoted strings and triple double quoted strings can be used for multi-line strings and string-expressions.

String name = 'Fred Flinstone'
def monthlySalary = 5000.00
println "Name: $name, salary: ${monthlySalary * 12}"

println '''This is
a multi-line
string'''

List and Map Literals

Lists literals can be constructed using comma separated values betwen [ ]. Map literals use comma separated key:value pairs.

Many built-in list methods exist such as map(), filter(), sort(), etc., for easy processing of list data.

def numbers = [1,2,3,4]
def person = [name:'Fred Flinstone', salary: 12 * 5000.00]

println "Name: ${person.name}, salary: ${person.salary}"

// Print square of each number
numbers.map{ x -> x * x }
.each{ x -> println x }

// Implicit it parameter
println "Sum: ${ numbers.map{ it * it }.sum() }

Optional Typing

Types can be provided and will be enforced by the compiler or can be omitted if dynamic typing is preferred. Note that functions return the value of the last expression if return is not used.

def fib(x) { x <= 2 ? 1 : fib(x - 1) + fib(x - 2) }

println "40th fibonacci number is ${fib(40)}"

Classes

Jactl provides the ability to define classes using a simplified syntax.

class Person {
String name
int age

String greeting() {
"My name is $name and I am $age years old"
}
}

class Student extends Person {
String university
String greeting() {
super.greeting() + " and I go to $university"
}
}

Person fred = new Student(name:'Fred Smith', age:19,
university:'University of Sydney')

println fred.greeting()

Regular Expressions

Jactl provides built-in support for regular expressions and capture variables $1, $2, etc., for capturing parts of the matched string.

def text = 'Product: MacBook Pro, Price: 3299.00, Quantity: 14'

// Extract data from text
if (text =~ /Product: (.*), Price: (.*), Quantity: (\d*)$/n) {
def product = $1
def totalValue = $2 * $3
println "Product: $product, value: $totalValue"
}