User Guide
Lite : mSQL?s Scripting Language
$uint_value = (uint)240983;$char_value = "Some text value";$real_value = 12.627;
|
|
|
|
|
|
Text representation of numeric string | 12 = "12" |
|
|
Real representation of integer value | 12 = 12.0 |
|
|
Text representation of real value | 123.45 = "123.45" |
|
|
Integer representation of real value | 123.45 = 123 |
The table below lists the available maths operators and
the data types to which they may be applied.
|
|
|
|
|
|
Addition |
|
|
|
|
Subtraction |
|
|
|
|
Division |
|
|
|
|
Multiplication |
|
|
|
Multiple parts of the conditional expression may be linked
together using logical ANDs and ORs. Like C, the syntax for an AND is &&
while the syntax for an OR is ||. As you will see in the example below,
Lite provides more flexibility than C in conditions containing text values.
You can compare two text values using the '==' equality test or the '!='
inequality test rather than having to use a function such as strcmp().
echo("The value is between 5 and 10\n");
}else{
echo("The value is not between 5 and 10\n");
}if ($charval == ""){
echo("The variable contains no value!!!\n");
}
$intval = $intval + 1;
}while ($charval != ""){
$charval = readln($fd);
if ($charval == "Hello")
{
}
{
statements
}
{
$result = $value1 + $value2;
return ( $value );
}
funct merge ( array $values, int $numVals)
{
$count = 0;
$result = "";
while ( $count < $numValues)
{
$count = $count + 1;
return ( $result );
}
funct sequence ( int $first, int $last )
{
$count = 0;
while ( $first < $last )
{
$first = $first + 1;
return ( $array );
}
Lite enforces a strict scope on variables used in user defined functions. Any variable referenced by the function is defined as a local variable in that function even if there is a global variable by the same name. Parameters are passed by value, not by reference, so any modification of the parameter variables is not reflected outside the scope of the function. The only way to modify the value of variables outside the scope of the function is by returning a value from the function or by explicitly referencing global variables as outlined below.
Lite supports the concept of explicitly accessible global variable by using a different syntax when referencing the variable. If a variable is referenced as $variable then it is a variable within the current scope (a local variable if it is referenced in a function, a global variable if referenced from the main code). If a variable is to be explicitly referenced as a global variable then it can be referenced as @variable rather than $variable (a preceeding "@" character rather than a "$" character). This will force the Lite symbol table management routines to access the global symbol table rather than the symbol table associated with the current execution scope.
/*
** Now we can use the functions from the "mylib" library
*/
$array = sequence(1,10);
$count = 0;
while ($count < # $array)
{
printf("Value %d is '%s'\n", $count, $array);
$count = $count + 1;
}
Library files are not like normal Lite script files. A
Lite script file is a plain ASCII text file that is parsed at run-time
by Lite. A library file contains pre-compiled versions of the Lite functions
that will load faster as they do not need to be re-parsed every time they
are used. A Lite library file is created by using the -l flag of the Lite
interpreter. If a set of functions was placed in a file called mylib.lite,
a compiled version of the library would be created using the syntax shown
below.
There are three points that should be noted about the use of Lite libraries. Firstly, it should be noted that a Lite library can only contain functions (i.e. it cannot contain any "main body" code that you would normally include in a script file). Secondly, like functions themselves, a library can only be loaded into a Lite script prior to the start of the main body code. Finally, the path given to the load command within the script does not enforce a known location for the library file. If you specify the library file as "mylib.lib" then Lite will expect the library file to exist in the current directory. You can of course provide a complete pathname rather than just a filename to the load command.