TScript is an object-oriented embeddable scripting language for C++ that supports hierarchical transient typed variables (TVariable). Its main design criterion is to create a scripting language that can interface with C++, transforming data and returning the result. This enables C++ applications to change their functionality after installation.
TVariable are hierarchical in nature and are very similar to XML, JavaScript and PHP variables.
The TVariable type is also transient as an Integer can be changed into an AString by assigning it a string value or by casting the variable to an AString. For example, after an integer variable has been created and used, it can be reassigned by equating it to an AString.
TVariables can also be used to hold an array of TVariables. Once a valid variable has been created, the array index subscripting notation can be used to transform it into an array, so for example the code - will create an array with four elements. The TVariable type for "list.type" will be that of a structure and each element of will be an Integer.
Class in TScript are similar to array in how TVariable handle them, but use strings as array scriptures. For example, the code - will create a structured variable where list. Monday is true and is false. In the native C++ code, structured TVariable elements are accessible in C++ by - or by either or in native code.
TScript implements concepts of inheritance and code encapsulation through defined variables. For example, the following code snippet show a defined variables and that supports a constructor.
variable Foo extends Bar{
public main(){
Integer minimum, maximum;
Bar(){
this.minimum = 1;
}
}
WString name;
Foo(WString name){
this.name = name;
this.Bar();
}
}
Foo foo(L"Goo");
System::MessageBox(foo.ToString());
}
Allowing functions to have a list of input and output variables that are separated by the semi column ":", changed the normal flow of how the function are called and used. This removes some of the need for using reference pointers to return multiple variables that is common in C/C++, and the use of references in most other scripting languages is actually prevented, forcing the use of a structure or array to return multiple values.
The second noticeable thing about the calling conventions is that now all functions have an integrated error handling purpose similar to and of C++ and Java. In TScript since all functions return an error, the return statement operates similar to the throw statement. For example, the statement:- return error = "Have an error message"; will terminate the function and return the error message. Alternatively the blank statement;- return; will terminate the function but not return any error.
text = text.Fragment(L"\n"); for(height = width = 0; height < text.length; height++){ if(width < text[height].length) width = text[height].length; }}
In many languages that use the syntax the error is returned via the catch statement and this can make the operational flow of the code awkward in situations where some errors are recoverable. TScript uses the notation that allows calling code to filter the error, potentially recovering from the error and returning to normal operation, or returning the error to its own calling function.
public main(){
if(!function()){ if(error != -1) return error; } System::MessageBox(L"function executed correctly");}
To counter this problem, TScript has been written with run-time linking. This is when the particular function called is dependent on the type of the variables when the function is called.
This is an unusual tactic that has some additional benefits. First it means that there is no need to declare functions before they are used, for example in C++ two functions may call one another, like and . In this situation, the needs to be prototyped in order for the to call it. TScript's run-time linking means the functions can be declared in any order without the need to prototype. This can make writing code much easier for less experienced programmers, allowing them to focus on the logic of the software and not the requirements of the language.
Run-time linking also enables the language to support run-time coding with methods like and . This enables TScript programs to write themselves. For example, when using the SOAP interface, the remote WSDL will be encoded into the script library, allowing the functions within to be called as if they were coded at design time. Additionally it is also possible to write code that can learn for itself, writing new functions when it needs it.
Operation system resources such as files, sockets and encryption keys are managed via a reference counting mechanism similar to .NET, so they will be released as soon as there are no variables containing their values.
This security architecture is designed to allow the running of scripts in a similar way to JavaScript while enabling the usefulness of more powerful scripting languages like Perl.
|
|