What does JualScript look like?

It looks exactly like JavaScript code.  Here is the content of one of the test files that will run on both the Jual VM and a JavaScript interpreter:

var szOut = "*";
var x = 0;
var y;
while (x < 10) {
    y = 0;
    while (y < 50) {
        szOut = (szOut + " " + y);
        if (y  == 20) { break; };
        y = y + 1;
    };
    szOut = (szOut + "n");
    x = x + 1;
    
    if (x == 6) { break; };
};
print (szOut);

What can I use JualScript for?
Here are some ideas I had in mind:
* It can be used as a text processing tool like awk or as an automation tool like JScript.
* It can be be used as a replacement for mod_lua, so that Apache can provide a light weight JavaScript-like server side scripting engine.
* It can help existing software already using the Lua engine (like World of War craft) transition from the relatively obscure Lua language to the more popular JavaScript language.

What are some of the differences in the syntax between JavaScript and JualScript?

In JualScript:

* Curly braces are required, even for single line code.
(Some consider this a good thing.  No more dangling if .. else problems!)
* You can not initialize multiple variables with a single var statement on the same line.  It is possible with Lua style syntax, but this is not recommended for compatibility. i.e.

var j=1, k=2;     // Works in JavaScript but not JualScript (AVOID)
var j,k = 1,2;    // Works in JualScript but not JavaScript (AVOID)
var j=1; var k=2; // Recommended way works in both

What are some of the other differences between JualScript and JavaScript?

There are many.  In JualScript:
* There is no special values like undefined and NaN – only null.
* Only false and null evaluate to a false condition.  All other values evaluate to true including: the number zero 0 and the empty string “”.
Make explicit comparisons in your conditional statements.
* Different error handling mechanism: pcall and xpcall vs try/catch/finally
* Different ways of prototyping and defining object classes.
(The one method of defining classes using closures can be used by both JualScript and JavaScript. See the example file 15_classes.js in the testsuite folder)
* String and Array’s do not have a length property.  Use the .size() method instead.

A summary of the key language features and the base library functions is listed in the file jual_reference.txt.

What differences do I need to watch out for when converting JavaScript code to JualScript?

* The most tricky thing to watch out for is string concatenation with the + operator. The difference in output is caused by automatic number coercion and conversion in the Lua VM. This simple loop will produce different results under JualScript and JavaScript:

var iList = "0";
for (i=1; i<10; i=i+1) {
    iList = iList + " " + i;
};
print(iList);

Javascript will produce the output:

0 1 2 3 4 5 6 7 8 9

while JualScript will simply output the number 45. To fix this behaviour will require a change in the VM code. No change has been done to maintain byte compatibility with the Lua VM.  The simple solution to this is to use the concat function rather than the ambiguous + operator. Alternatively, start the loop with a value that can not be coerced into a number e.g. replacing the initial variable declaration to var iList=”*”; will produce the same results in both languages.

What features from Lua will work in JualScript?

Every feature not modifed to make Lua behave like JavaScript should work in JualScript.  Here are some that may be useful:

* String formating using sprintf format. Use the built-in Lua string.format() function.
* Goto statements:  see example file test_gotostat.js in the samples folder
* Co-routines:  see example file test_coroutines.js in samples folder