Intro

Every script consists of executable code and data, is similar to a single program running in an operation system. Memory used for code is allocated internally, no access is possible. Data of a typical script may be placed on the stack, be managed , or allocated by the user and only used.

A script is represented by ISCVMScript interface. You get a compiled script by calling LoadScript or CompileScript method of the virtual machine. It has an internal reference counter, that allows to track access. If the reference counter reaches 0 or less the script is deleted. You can increase this counter by IncRef method, access is released by Release method. You must call Release at least one - to destroy the script. When you get the script it has reference counter set to 0. The best method is to use smart pointer that automate this process (see Total Overscript example).

You can place the code in functions or in the main block. Any code placed out of functions is put into the main block (it is not defined explicitly) and executed when Execute() of ISCVMScript interface method called.

Variables

A script contains stack, managed and native variables. They are described in separated chapters. Variable definition is similar to C++ definition, may be written in the following ways:

  1. typemod type name; - stack variable, default contructor called
  2. typemod type(params); - stack parametrized constructor
  3. typemod type name = init_expr, name2 = init_expr; - many variables in one line
  4. typemod type *name = NULL; - native pointer, must be initalized
  5. typemod type **name = ptrobj; - native pointer to pointer, must be initalized, ptrobj - some other pointer
  6. typemod type &name = refobj; - reference, must be initialize, refobj - some object
  7. typemod type ^name; - managed pointer
  8. typemod type ^^name; - managed pointer to pointer

typemod is an optional type modification (const, shared, static)

type is the name of the type

name is a valid variable name (starts with : A-Z, a-z, _, may contain also numbers 0-9)

Pointers may point to some value or other pointers, but you cannot mix pointer type (managed, and native)

Some examples below:


Int x;                  //simple stack variable
const Vec2f v;          //vector with default constructor
const Vec2f v(1, 1);    //vector with parametrized constructor
const Vec3f &vr = v;   //reference to v - references must be initialized
Vec3 ^vm = new Vec3(1, 1); //managed variable created on ilitialization
Vec3 ^vm;               //null managed variable 
Vec3 *vm = NULL;        //native pointer pointing to NULL - native pointers must be initalized


Functions

Functions are defined in the main block of a script. They definition is the same like C++ functions. They are used in the same way like exported C++ functions.

Some examples below:



void Print(PCStr s)  //definition of a function taking const char* argument
{
 ...
}

Print("text");      //print some text



Int Inc(Int v)      //increment argument
{
  return ++v;
}

Script states

A script has always some state. Not all operation are possible in all states. Scripts state is one of following enums (SCVMSCRIPTSTATE).