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.
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:
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 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; }
A script has always some state. Not all operation are possible in all states. Scripts state is one of following enums (SCVMSCRIPTSTATE).