Jump to content

TScript

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by DallasClarke (talk | contribs) at 22:57, 25 October 2012 (Defined variables (classes)). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
TScript
Developer(s)Ekky Software
Stable release
1.4 / July 1, 2012 (2012-07-01)[1]
Written inC++
Operating systemWindows & Linux
TypeScripting language
LicenseFree (Proprietary)
Websitewww.ekkysoftware.com

TScript is an object oriented embeddable scripting language for C++ that support hierarchical transient typed variables (TVariable). Its main design criteria 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 post installation.

Hello world example

The basic "Hello World!" TScript example.

CTScript ts;
ts.SetParameter(CTScript::SOURCE_STRING,0,TEXT("main(){")
TEXT("   System::MessageBox(L\"Hello World!\");")
TEXT("}"));
ts.ExecuteStaticMethod();

TVariables

The standard variables can be formed as fixed data such as a Boolean, Integer or Decimal and a variable length variable such as an ASCII string, wide character string or a binary string. The type of the data can be used to define variable or the type can be explicitly declared, so for example the code - "variable myInteger = 0;" will create a variable called myInteger and assign it the value of zero. An Integer type can also be declared as - "Integer myInteger;" and its default value will be set to zero.

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 - "variable list = {0,2,4,6};" will create an array with four elements. The TVariable type for "list.type" will be that of a structure and each element of "list[0].type" 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 - "variable list = {"Monday" =>; true, "Tuesday" => false};" will create a structured variable where list. Monday is true and list.Tuesday is false. In the native C++ code, structured TVariable elements are accessible by - list["Monday"].

Defined variables (classes)

Supporting hierarchical variables, TScript is able to store primitive variables or complex variables within the same structure. This removes any requirement for a unique difference between primitives and structured data, and the class structure becomes more a logical grouping of functionality rather than data storage.

TScript implements concepts of inheritance and code encapsulation through defined variables. For example the following code snippet show a defined variables ‘Foo’ and ‘Bar’ that supports a constructor.

variable Bar{
   Integer minimum, maximum;
   Bar(){
      this.Minimum = 1;
   }
}

variable Foo extends Bar{
   WString name;
   Foo(WString name){
      this.name = name;
      this.Bar();
   }
}

public main(){
   Foo foo(L"Goo");
   System::MessageBox(foo.ToString());
}

Function declarations

The first striking feature of TScript is the function declarations. The standard function in nearly all other computer language are in the form:- [output variable] <function name>([input variable],….), while in TScript this pattern has been change to the form:- <function name>([input variable],… :[output variable],..). This change has done two things, first it allows multiple output variables and secondly it changes the return statement to an error handling function.

Allowing functions to have a list of input and output variables that are separated by the semi column “:”, changes the normal follow 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++, but the use of references in most other scripting languages is actually prevented.

The second noticeable thing about the calling conventions is that now all functions have an integrated error handling purpose similar to try{…}catch(…){…} and trow new Exception() 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.

Example of multiple return values

public TextExtent(WString text : Integer width, Integer height){
   text = text.Fragment(L"\n");
   for(height = width = 0; height < text.length; height++){
      if(width < text[height].length) width = text[height].length;
   }
}

Run-time linking

C++ support function overloading which enables functions to have the same name while being differentiated by their input parameters. This causes TScript an issue while supporting loose type variables, as there is no way to tell what the type of a variable is until the software is being executed.

To counter this problem, TScript has been written with run-time linking. This is when the particular function called is depend 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 void Foo(){ Bar();} and void Bar(){Bar();}. In this situation the Bar() needs to be prototyped in order for the Foo() to call it. TScript's run-time linking means the function 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 method like AddMethod and AddDefinedVariable. This enables TScript programs to write themselves. For example when using the SOAP interface, the remote WSDL will be encode into the script library, allowing the functions within to be called as if they where coded at design time. Additionally it is also possible to write code that can learn for itself, writing new functions when it needs it.

Dynamically linking libraries

TScript is among a small group is scripting languages that provide the functionality to dynamically load and link to existing shared libraries. Java through its JNI and VB6 are two other scripting languages that enable code to be written that would load a third party library and execute through its native interface. This gives TScript the ability to use a wealth of pre-existing functionality and code written in different languages and this can be done without any need to change the shared library’s interface or to be compiled with the source code.

Memory management

TScript uses the standard C++ class encapsulation to allocate and de-allocate memory resources. This means that all allocated memory is released when the variable containing it is destroyed and operated differently to the Garbage Collection model of Java or the reference counting model of .NET languages.

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.

Pro-active security

With the ability to load existing shared libraries, script can access all privileges granted to the user who executes it. To guard against malicious code, all resources beyond the basic memory allocation are required to be granted to each script. This also includes the ability to use message boxes to prompt the user, read and/or write access to any file or directory, or using the Internet connection.

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.


References