Skip to content

twineworks/tweakflow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tweakflow - safe embeddable scripting for the JVM

Java 8+ License Maven Central AppVeyor Build status Join the chat at https://gitter.im/twineworks/tweakflow

Applications can use tweakflow to expose runtime information to an expression-based scripting runtime, allowing users to safely interact with the provided data and collect scripted results.

Tweakflow keeps the application in control of the data exchange. Users cannot arbitrarily call into application internals.

Requirements

Java 8 or later is required. Builds are tested against JDK 8, 11, 13, 15 and 17.

Getting the jar

Get the latest release jar from github, or from maven central.

Getting started

Start the REPL using:

$ java -jar tweakflow-1.4.4.jar repl

Start typing expressions for the REPL to evaluate:

tweakflow interactive shell    \? for help, \q to quit
std.tf> 1+2
3

std.tf> "Hello " .. "World"
"Hello World"

std.tf> data.map([1, 2, 3], (x) -> x*x)
[1, 4, 9]

See the getting started guide for a short guided tour of language features.

Syntax Highlighting

Language features

A simple computation model

Tweakflow has values and functions acting on them. All language constructs like variables, libraries, and modules merely serve to name and organize values and functions into sensible groups. Application users do not have to learn any programming paradigms to start using tweakflow expressions.

Dynamically typed

Tweakflow is a dynamically typed language. Data types include booleans, strings, longs, doubles, exact decimal numbers, datetimes and functions, as well as nestable lists and dictionaries. All data types have literal notations.

All data is immutable

All values in tweakflow are immutable. It is always safe to pass values between user expressions and the host application without worrying about mutable state or object identity.

All functions are pure

All functions in tweakflow are pure and free of observable side-effects. A tweakflow function, given the same arguments, will always return the same result. The host application must take care of all non-pure operations like file I/O.

Batteries included

Tweakflow comes with a standard library that allows users to perform common tasks when working with data. Your application can limit or extend the standard library to suit its needs.

Test framework included

Tweakflow comes with an extensible spec framework similar to mocha, rspec, etc. The tests for the standard library are implemented with it.

Automatic dependency tracking

When the application changes an input variable, tweakflow efficiently recalculates the values of any user variables that depend on it. Much like a spreadsheet application updates dependent formula cells when a cell changes.

Inline documentation and meta-data

Tweakflow supports documentation annotations as well as arbitrary meta-data on variables, libraries and modules. This feature supports interactive help as well as automated generation of project documentation.

Using tweakflow standalone

Tweakflow is designed to be an expression language embedded in a bigger application. Much like formula languages are embedded in spreadsheet applications. However, for prototyping, development and testing, it can be handy to invoke tweakflow directly.

See the tools guide, for more information on the tweakflow REPL, runner, and documentation tool.

Embedding

Evaluating simple expressions is as easy as:

TweakFlow.evaluate("1+2"); // returns the Value 3

Or it can be more sophisticated, providing users with application variables they can reference. Your app is in control of functions and variables available to user expressions.

The host application can allow users to define variables, group them into libraries and even separate modules for reuse across their projects. How much sophistication is available to users depends on how much your application wants to expose.

We've embedded tweakflow as the expression engine in our data automation tool: Tweakstreet

See the embedding guide for more information and examples.

License

Tweakflow uses the business friendly MIT license.

Support

Open source does not mean you're on your own. Tweakflow is developed by Twineworks GmbH. Twineworks offers commercial support and consulting services. Contact us if you'd like us to help with a project.