Tiny embeddable scripting language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
sa 71763e70b2 Remove now redundant function 23 hours ago
libraries Remove now redundant function 23 hours ago
libsatl Remove now redundant function 23 hours ago
libwasm switch cases break by default, add fallthrough keyword 1 month ago
manual Remove now redundant function 23 hours ago
samples Cleanup 1 month ago
satld JSON supports Unicode escape sequences 2 weeks ago
serenity/Ports/satl Cleanup 6 months ago
sly Cleanup 1 week ago
src Add Range expression (`..` operator) which returns a table 24 hours ago
thirdparty Refactoring, tests 2 weeks ago
.clang-format Add watches 9 months ago
.gitignore Remove *.txt 6 months ago
CMakeLists.txt Refactoring, tests 2 weeks ago
LICENSE Make it AGPL 7 months ago
PKGBUILD Add some functions 2 months ago
README.md Simplify functions 1 week ago
satl.xml switch cases break by default, add fallthrough keyword 1 month ago
sly.1 Pump version 2 months ago

README.md

sa::tl

Let's make a tiny scripting language, because ... why not.

Sly

Features

  • Tiny embeddable script interpreter in under 10k LOC (for comparison, Lua has around 30k LOC) with exception handling, rudimentary OOP features, operator overloading, simple debugger, type safe binding API for C++ and more.
  • Handwritten lexer and recursive descent parser.
  • AST interpreter.
  • There is no main function. A script is a sequence of statements.
  • Strictly single threaded, that's a feature. Of course, it is possible to implement threading/concurrency with a library, but it would be a challenge to make it not-so-crashy.
  • Supports line comments (//) and block comments (/* multiline comment */).
  • All variables must be initialized.
  • It has the following types: null, bool, integer, float, string, function, table and object (C++ object) with optional type hinting.
  • Variables can not change their types, they get their type by initializing them.
  • Number literals: Hex (0x2a), Oct (0o24), Bin (0b101010), Dec (3.1415).
  • Other special literals: null, true, false.
  • Statements: if, switch, for, foreach, do, while, function, try, defer.
  • First class functions, Higher-order functions, Nested functions with lexical scoping and non-local variables (Closures).
  • Strings delimiter is either single or double quotes.
  • All strings can be multiline.
  • String concatenation with the + operator (str = "hello" + " " + "friends!"). String multiplication with the * operator: str = "foo" * 3; // str == "foofoofoo".
  • Raw string literals like C++: str = R"string(this is a raw string anything goes here " ')string".
  • Basic Unicode support
  • Normal strings (i.e. non raw strings) can contain escape sequences.
  • Template literals (delimited with backticks): `string text ${expression} string text`
  • Short-circuit evaluation
  • Operator overloading for tables and C++ classes.
  • Easy way to add custom functions.
  • Easy and type safe binding of C++ classes with functions, properties and operators with optional Garbage Collector for managing the lifetime of C ++ objects.
  • UI library, HTTP library, PostgreSQL client library, Graphics library.
  • Extensible with custom libraries
  • LSP compatible Language Server, works at least with Kate and QtCreator
  • KSyntaxHighlighting definition

License

AGPL 3.0

Requirements

  • C++20
  • CMake
  • Catch2, on Arch you can install it with sudo pacman -S catch2
  • Linux
  • ccache (optional)

Some libraries require additional packages.

Build

$ git clone https://codeberg.org/trill/satl.git
$ cd satl
$ mkdir build && cd build
$ cmake ..
$ make

Optional:

$ sudo make install

On Arch you may want to run CMake with:

$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr

CMake options

  • SATL_ENABLE_ASSERT Enable assert() in Release mode (default ON)
  • SATL_TESTS Build unit tests (default ON)
  • SATL_MATHLIB Build math library (default ON)
  • SATL_OSLIB Build OS library (default ON)
  • SATL_IOLIB Build IO library (default ON)
  • SATL_REGEXLIB Build regular expression library (default ON)
  • SATL_PGLIB Build PostgreSQL client library (default ON)
  • SATL_UILIB Build UI library, requires GTK (default ON)
  • SATL_GFXLIB Build Graphics library, requires stb (default ON)
  • SATL_SAMPLELIB Build sample extension library (default OFF)
  • SATL_INSTALLMAN Install man page (default ON)
  • SATL_READLINE Use readline library (default ON)

Running the tests

When built with SATL_TESTS you can run the tests with the following command in the build directory:

$ make test

When using ninja:

$ ninja test

Usage

See the Manual for documentation attached to the Release.

Example

function sub(a, b)
{
    return a - b;
}

function doFunc(func, a, b)
{
    return func(a, b);
}

// Pass function as named argument
sum = doFunc(sub, 2, 3);
println(sum);

// Inline defined function
sum = doFunc(function(a, b) { return a + b; }, 1, 2);
println(sum);