2 - The Language

Keywords

break continue return function global local var if else for do while exit

Working code looks a little like the following sample.

function demo(arg1) {
        global x=1;
        # you don't actually need local or var, but it makes the code clearer
        local y=2;
        var z=3;

        for (i=0;i<10;i++) {
                if (i<5) {
                        print("less than half ", i, "\n");
                } else if (i==5) {
                        print("half\n");
                } else {
                        print("more than half ", i, "\n");
                }
                if (i==arg1) break;
        }
        return;
}
demo(8);

break (accepts an optional unbracketed number arg to define the number of levels to break)
still need to add switch and goto..

Operators

= + ++ += - -- -= * *= / /= == != <= >= < > % & | ^ && || !

Strings can also be handled using the slightly shorter list of ops: = + += == != <= >= < >

The statement var x="a"+"b"; will set x to "ab".

Tables have considerably less ops: = {}

function subf() { return 69; }
var pi = math.asin(1)*2;
var table = {
	{ a1="x", b = pi, [12]=41, [1]=42, 43, 'blah', subf() },
	{ "x", 'y', x = 41, 42, 43, 'blah', [5]=12, heh=";-)" }
};

setting a var's value to null will completely free the value and effectively make the var non-existant