LIL Scripting Language

LIL Scripting Language

Overview

LIL, or little interpretted language, is a scripting language that somewhat resembles TCL. The language is easy to embed into other programs, as it only conists of a small C and header file.

The homepage of LIL can be found at http://runtimeterror.com/tech/lil/.

Most of the documentation for syntax and API can be found here: http://runtimeterror.com/tech/lil/readme.txt.

Syntax Examples

Hello World

Hello world:

<<hello.lil>>=
print hello world

Function starts with the first word, arguments follow. Arguments are words separated by spaces.

Arithmetic

Arithmetic is done with expr. Bitwise operations work! It seems attention to operator precedence is also here as well.

print [expr 4 + 4 * 2]
print [1 << 4]

Line Breaks

A new function starts at each line break by default. Alternatively, semi-colons can be used to have multiple function calls on one line.

# print hi there on two lines
print hi
print there

# same thing, but put the calls on one line
print hi ;print there

# break up function into lines
print hi \
    there

Functions

func foo {a b} {print $a $b}

Variables

Variables are set with set.

set x 4; print $x

Arrays/Lists

LIL calls these things lists.

set foo {paul john george}

To get the number of items from a list, run count.

print [count $foo]

To get an item from a list, use index.

print [index $foo 0]

Use append to append an item to a list.

append foo ringo

For Loop

for {set i 0} {$i < 10} {inc i} {
    print $i
}

Command line arguments

Stored as a list via $argv.

Block Comments

Separated by ## and ##

##
hello!
this is a block comment!##

##
this is
another
block
comment
##

API Usage Examples

Here's a really quick "hello world" API example I made:

<<lil_api_hello.c>>=
#include <stdlib.h>
#include <stdio.h>
#include "lil.h"

static lil_value_t foo(lil_t lil, size_t argc, lil_value_t *argv)
{
    printf("hello from C!\n");
    printf("nargs: %ld\n", argc);
    return NULL;
}

int main(int argc, char *argv[])
{
    lil_t lil;
    lil_value_t val;

    lil = lil_new();

    val = lil_parse(lil, "print hello there!\n", 19, 0);
    lil_free_value(val);

    lil_register(lil, "foo", foo);

    val = lil_parse(lil, "foo 1.234\n", 10, 0);
    lil_free_value(val);

    lil_free(lil);
    return 0;
}

home | index