Abstact of paxScript User's Guide


paxScript data types

All paxScript languages are loosely typed ones. Loosely typed means you do not have to declare the data types of variables explicitly. All pax-languages have the following standard (base) types: Boolean, Byte, SmallInt, ShortInt, Word, Integer, Cardinal, Int64, Double, String, Variant. (These types are named as bool, byte, sbyte, short, short, int, uint, long, double, string, variant in paxC).

Variables

You have to declare variables explicitly in your scripts using the Dim statement (paxBasic) or Var statement (paxC, paxPascal). These statements create variables.

Variables are initialised to Undefined when created. But you can assign the variable with another value. For example:

paxBasic:

Dim X As String = "abc" 
Dim Y = [100, 200]
Dim Z = new MyNamespace.AClass()

paxC:

string X = "abc";
var Y = [100, 200];
var Z = new MyNamespace.AClass();

paxPascal:

var 
  X: String = 'abc';
  Y = [100, 200];
  Z = MyNamespace.AClass.Create();
Here Y has been assigned by the zero-based array which contains 2 elements. The variable Z above was assigned by object.

You can create a multi-dimensional zero-based arrays without having to initialise it. For example:

Dim X(10, 4)                    'paxBasic
var 
  X[10, 4];                     //paxC, paxPascal 
In a two-dimensional array, the first number is always the number of rows; the second number is the number of columns.

Scope of Variables

A variable's scope is determined by where you declare it.

When you declare a variable within a procedure, only code within that procedure can access or change the value of that variable. It has local scope and is a procedure-level variable.

When you declare a variable within a class body, only code within that class can access or change the value of that variable. Besides you make it recognizable to all the methods in the class with the following exception: if the variable was declared as non-shared one, it is not recognizable to all shared methods in the class.

When you declare a variable within a namespace, only code within that namespace can access or change the value of that variable. Besides you make it recognizable to all the classes and their methods in the namespace.

If you declare a variable outside all procedures, namespaces and classes, you make it recognizable to all the procedures and methods in your script. This is a script-level variable, and it has script-level scope.

Example (paxBasic)

Namespace Shapes
  Dim ShapeCount, ShapeList[100]

  Sub RegisterShape(S)
    ShapeCount += 1
    ShapeList[ShapeCount] = S 
  End Sub
   
  Class Point
    Dim X, Y
    Sub New(X, Y)
      Me.X = X
      Me.Y = Y
      RegisterShape(Me)
    End Sub
  End Class

  Class Square
    Dim X1, Y1, X2, Y2
    Sub New(X1, Y1, X2, Y2)
      Me.X1 = X1
      Me.Y1 = Y1
      Me.X2 = X2
      Me.Y2 = Y2
      RegisterShape(Me)
    End Sub
  End Class
End Namespace

Dim P = Shapes.Point(3, 5)
print P

Here P is script-level variable, ShapeCount, ShapeList are namespace-level variables, X, Y, X1, Y1, X2, Y2 are class-level non-shared variables (field members), S is procedure-level variable. To distinguish non-shared class members and procedure-level variables, the MyBase keyword is used. (Check for X, Y usage in the Point.New procedure as an example).

Life time of Variables

The lifetime of a variable depends on how long it exists. The lifetime of a script-level variable, namespace-level variable, or a variable declared at class-level as shared (static) extends from the time it is declared until the time the script is finished running. At procedure level, a variable exists only as long as you are in the procedure. When the procedure exits, the variable is destroyed.

Controlling Program Execution

You can control the flow of your scripts with ordinary set of conditional statements and looping statements which are pesent in such languages as VB/VB.NET, C++, C#, JavaScript, Pascal. See Progammer Reference to get more information.

Working with Classes and Namespaces

All pax-scripting languages support such concepts of the modern programming as namespaces, nested classes, inheritance, static(shared) members, indexed properties, delegates. If you are already familiar with the family of .NET languages such as VB.NET, C#, JScript.NET, you already know how to apply these concepts in pax-languages.


Copyright © 1999-2006 VIRT Laboratory. All rights reserved.