Variables
Variables are created on demand and don't need to be explicitly declared. Sometimes the host will insert
known global variables before the script is run, but that usage pattern is declining as "Main" functions
are now used, that allow parameters from outside the script to be passed in via explicit method arguments.
The variables themselves are based on a variant data type, that can contain integers, strings and various
pointer types. There is no dereference operator needed to use a pointer type variable. Pointer arithmetic
is not supported, as generally the pointers are to single class objects, not arrays of objects. That said
there are List and HashTable sub-types to the variables, but no array as such.
Scope
There are 3 fixed scopes: global, local, register. Although in practice when writting code you only ever
deal with global and local. Unlike C, there are no extra scope levels inside { } blocks inside a function.
Variables defined in that function (including it's arguments) are visible throughout that function.
Global variables are defined outside of a function scope and are visible everywhere.
Constructs
Scripts are constructed from these primitives:
-
if (expression) { statements; }
[else if (expression) { statements; }]
[else { statements; }]
-
while (expression) { statements; }
-
for (initial_expression; condition_expression; iterate_expression) { statements; }
-
function method_name([arg1[,arg2]]) { statements; }
-
return expression;
-
expression;
Operators
These operators can be used in expressions:
= | Assign
|
+ | Plus
|
- | Minus
|
* | Multiply
|
/ | Divide
|
% | Mod
|
< | LessThan
|
<= | LessThanEqual
|
> | GreaterThan
|
>= | GreaterThanEqual
|
== | Equals
|
!= | Not Equals
|
+= | Plus Equals
|
-= | Minus Equals
|
*= | Multiply Equals
|
/= | Divide Equals
|
++ | Post Increment
|
-- | Post Decrement
|
++ | Pre Increment
|
-- | Pre Decrement
|
&& | And
|
|| | Or
|
! | Not
|
. | Object member reference
|
Objects
Some variant types allow the referencing of object members via the '.' operator. The available members depends
on the variant type:
- DOM:
- "member_name" - depends on the object, they all have different member names.
For example see the Scribe Object Model.
- String:
- Length - the length of the string in bytes (strings are utf-8).
- Int - the string as an int (atoi).
- Float - the string as a double (atof).
- List and HashTable:
- Length - the number of objects in the container.
- DateTime:
- Year - just the year as an int.
- Month - just the month as an int.
- Day - just the day as an int.
- Hour - just the hour as an int.
- Minute - just the minute as an int.
- Second - just the second as an int.
- Date - the date part as a string.
- Time - the time part as a string.
- DateTime - the date and time as a string.
- Image (GSurface):
- x - The width in pixels.
- y - The height in pixels.
- Bits - The bit depth.
List
The list object type allows you to store a bunch of objects in a variable (of the same variant type).
To get the length of the list, use
var_name.length, and to access the various
members use
var_name[
index_expression] where the exp
evaluates to an integer. If you don't specify an
integer then you'll get back a NULL variable as the
result.
HashTable
HashTable's are very similar to lists, in that they allow you to store a objects in a variable.
To get the number of objects in the hash table, use
var_name.length,
and to access the various members use
var_name[
index_expression]
where the exp evaluates to an
string. If you don't specify a string then you'll get back a NULL
variable as the result.