In this tutorial, you will find out how to use the Sling development tools and how to create, compile and run small programs written in the Sling programming language. The content is presented as a consecutive serious of small programs, each of which demonstrates a particular feature or ability of the Sling language.

Install Eqela

If you have not yet done so, install the latest version of the Eqela Runtime:

Your first program

Open your favorite text editor, and write the following program as the contents (If you do not have a favorite text editor yet, try Visual Studio Code):


	PRINT "Hello World"
	return 0

Save the file as "". Then open a command line to compile and execute your program:

eqela eqela:slingbuild:r18 run

The slingbuild module is used here for convenience. The purpose of the slingbuild module is precisely to offer convenient, easy to use commands for common compilation tasks. Under the hood, slingbuild will still call The Sling compiler to perform the actual compilation.

Note also that the above command will compile and execute our program using the .NET Core framework, which is used by default for command line applications with slingbuild. The first time you execute this command, the Eqela Runtime will download the Sling compiler and the .NET Core runtime environment and development tools, which might take some time. Also, on the first run of the .NET Core environment, some amount of initialization takes place, which also takes a little bit of time. On subsequent runs, when everything is set up, the execution will then be much faster.

Console program with user input

For a slightly more complex console program example, type the following in a file named "":


import capex.console

	var terminal = Terminal.forCurrent()
	var data = new vector<string>
	loop {
		foreach str in data:
			terminal.print("Content: " .. str .. "\n")
		terminal.print("Enter text: ")
		var v = terminal.readLine()
		if not v:
		data += v

Execute the program exactly the same way as our original:

eqela eqela:slingbuild:r18 run

This program uses the Terminal class from the capex.console module, which is part of The Jkop Framework. The slingbuild tool will automatically download, install, compile and use the appropriate version of the Jkop libraries upon compiling. The program also makes uses of a vector of strings, loop and foreach.

Your first GUI program

The following program represents a very simple graphical application that has a user interface. User interfaces in Sling programs are usually implemented using Jkop Widgets, which are used to implement the graphical interface components.

Save the following code to a file named "":

class #widget #main:

import cave.ui

ui LayerWidget
	LabelWidget myLabel {
		text = "Hello World"

Then compile the code to an HTML5 application with the following command:

eqela eqela:slingbuild:r18 buildWeb -prefilter=@caveui

After compilation, you will find a file named "index.html" in the directory "build/HelloGuiWidget/web". You can open this file in your web browser.

There are two custom modifiers used in the program: #widget and #main. The #widget modifier enables the use of user interface expressions in the class definition. This is the "ui" statement you see there. Without the use of a UI expression, the graphical interface would need to be created using method and class instantiation calls. Which is also definitely possible.

The #main modifier informs the compiler that this is the "main" class of the application, and that the execution should start here.

You will also notice in the compile command that we have added a "prefilter" directive there. This is how we tell the compiler to add a custom compilation transformation to the code prior to actual compiling. In this case, we add the "@caveui" custom filter, which is responsible for converting the UI expressions to equivalent code that actually creates the user interface. See The Sling compiler for more details about custom filters for slingc.

Compiling to Android and iOS

The following separate tutorials will guide you through compiling Sling applications for mobile platforms:

Compiling Sling applications for Android

Compiling Sling applications for iOS

What next?

Sling Tutorials: Learn how to develop in Sling

Twitter Facebook LinkedIn Youtube Slideshare Github