LIL is a Language Make games, nicely

Functions and variables

Let's build something slightly more complicated. We are going to create and call our first function. Create a new file called "fns.lil".

Inside, add the following code:

fn sayHello {
    print "Hello world";
}

sayHello();

The last line in this example is what's known as top level code. The compiler will put these into a function which gets called in the initialization phase of your app.

Long story short, if we run this it will print "Hello world" to the console.

Variables

Variables are like boxes which contain information. You can specify the type of the variable, which means what kind of information can be stored there. You also give it a name, so that other parts of the code can refer to it. We can change our code a bit:

fn sayHello {
    var helloStr: "Hello world";
    print helloStr;
}

sayHello();

Again, if we run this it will print "Hello world" to the console.

Arguments

Now, we don't have to alway use strings, so let's get a bit mathy:

fn printNums ( var.i64 foo; var.i64 bar ) {
    print foo + bar;
}

printNums(100, 333);

The output in this case will be "433". As you can see, we used variables as parameters of the function, and we pass the two values that, inside of the function, will be summed together and then printed. In this case, we specified the type of the variables, which you should do most of the time, except where it is obvious what type it is going to be, such as in the previous examples.

One argument call

There is a nice syntax for function calls that only have one argument. Instead of using parentheses, you simply write a space followed by the argument. Like so:

fn myTest ( var.f64 foo ) {
    print foo;
}

myTest 0.314159265359;