TScript

Last updated
TScript
Developer(s) Ekky Software
Stable release
1.4 / July 1, 2012 (2012-07-01) [1]
Written in C++
Operating system Windows and Linux
Type Scripting language
License Free (proprietary)
Website www.ekkysoftware.com

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.

Contents

Hello world example

The basic "Hello World!" TScript example.

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

TVariables

The standard variable [2] 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 - variablelist={"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 in C++ by - list["Monday"]; or by either list.Monday or list["Monday"] in native code.

Defined variables (classes)

Supporting hierarchical variables, TScript is able to store both primitive and complex variables within the same variable structure. [3] This removes any requirement for any unique difference between primitives and structured data, therefore making the class structure a logical grouping of functionality rather than data storage type.

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.

variableBar{Integerminimum,maximum;Bar(){this.minimum=1;}}variableFooextendsBar{WStringname;Foo(WStringname){this.name=name;this.Bar();}}publicmain(){Foofoo(L"Goo");System::MessageBox(foo.ToString());}

Function declarations

Another striking feature of TScript is the function declarations, [4] which use output parameters rather than return values, and provide syntactic support for these. The standard function in many procedural languages, following Algol, is of the form:

[return type] <function name>([input variable], ...).

In TScript this pattern has been changed to the form:

<function name>([input variable],... :[output variable],...).

This change has done two things, first it allows multiple output variables and secondly it changed 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 ":", 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 try{}catch(){} and thrownewException() 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

publicTextExtent(WStringtext:Integerwidth,Integerheight){text=text.Fragment(L"\n");for(height=width=0;height<text.length;height++){if(width<text[height].length)width=text[height].length;}}

Shorthand notation

For convenience TScript offers a shorthand function calling in the situation where there is only one returned variable. This notation of will substitute the case of function(:variable);forvariable=function();. This short notation prevents the calling code from catching any errors and they will automatically be return to the parental calling code.

Error handling

Error handling in many other languages is done through the use of exceptions. TScript uses a similar process of error handling, [5] although slightly different. TScript has a global error variable similar to the traditional errno in C, although the error variable in TScript is capable to holding both an error code and a detailed error message.

In many languages that use the try{...}catch(...){...} 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 if(...){...}else{...} 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.

Example of return and handling errors

function(){returnerror=-1;}publicmain(){if(!function()){if(error!=-1)returnerror;}System::MessageBox(L"function executed correctly");}

Run-time linking

C++ supports 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 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 voidFoo(){Bar();} and voidBar(){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 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 AddMethod and AddDefinedVariable. 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.

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 from 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.

Related Research Articles

In programming languages, a closure, also lexical closure or function closure, is a technique for implementing lexically scoped name binding in a language with first-class functions. Operationally, a closure is a record storing a function together with an environment. The environment is a mapping associating each free variable of the function with the value or reference to which the name was bound when the closure was created. Unlike a plain function, a closure allows the function to access those captured variables through the closure's copies of their values or references, even when the function is invoked outside their scope.

In computer programming, a parameter or a formal argument is a special kind of variable used in a subroutine to refer to one of the pieces of data provided as input to the subroutine. These pieces of data are the values of the arguments with which the subroutine is going to be called/invoked. An ordered list of parameters is usually included in the definition of a subroutine, so that, each time the subroutine is called, its arguments for that call are evaluated, and the resulting values can be assigned to the corresponding parameters.

<span class="mw-page-title-main">Conditional (computer programming)</span> Control flow statement that executes code according to some condition(s)

In computer science, conditionals are programming language commands for handling decisions. Specifically, conditionals perform different computations or actions depending on whether a programmer-defined Boolean condition evaluates to true or false. In terms of control flow, the decision is always achieved by selectively altering the control flow based on some condition . Although dynamic dispatch is not usually classified as a conditional construct, it is another way to select between alternatives at runtime. Conditional statements are the checkpoints in the programe that determines behaviour according to situation.

In some programming languages, eval, short for the English evaluate, is a function which evaluates a string as though it were an expression in the language, and returns a result; in others, it executes multiple lines of code as though they had been included instead of the line including the eval. The input to eval is not necessarily a string; it may be structured representation of code, such as an abstract syntax tree, or of special type such as code. The analog for a statement is exec, which executes a string as if it were a statement; in some languages, such as Python, both are present, while in other languages only one of either eval or exec is.

<span class="mw-page-title-main">Java syntax</span> Set of rules defining correctly structured program

The syntax of Java is the set of rules defining how a Java program is written and interpreted.

In computer programming, a sigil is a symbol affixed to a variable name, showing the variable's datatype or scope, usually a prefix, as in $foo, where $ is the sigil.

In computer programming, an entry point is the place in a program where the execution of a program begins, and where the program has access to command line arguments.

In mathematics and in computer programming, a variadic function is a function of indefinite arity, i.e., one which accepts a variable number of arguments. Support for variadic functions differs widely among programming languages.

In some programming languages, const is a type qualifier that indicates that the data is read-only. While this can be used to declare constants, const in the C family of languages differs from similar constructs in other languages in being part of the type, and thus has complicated behavior when combined with pointers, references, composite data types, and type-checking. In other languages, the data is not in a single memory location, but copied at compile time on each use. Languages which use it include C, C++, D, JavaScript, Julia, and Rust.

<span class="mw-page-title-main">Scala (programming language)</span> General-purpose programming language

Scala is a strong statically typed high-level general-purpose programming language that supports both object-oriented programming and functional programming. Designed to be concise, many of Scala's design decisions are aimed to address criticisms of Java.

Exception handling syntax is the set of keywords and/or structures provided by a computer programming language to allow exception handling, which separates the handling of errors that arise during a program's operation from its ordinary processes. Syntax for exception handling varies between programming languages, partly to cover semantic differences but largely to fit into each language's overall syntactic structure. Some languages do not call the relevant concept "exception handling"; others may not have direct facilities for it, but can still provide means to implement it.

<span class="mw-page-title-main">JavaScript syntax</span> Set of rules defining correctly structured programs

The syntax of JavaScript is the set of rules that define a correctly structured JavaScript program.

this, self, and Me are keywords used in some computer programming languages to refer to the object, class, or other entity of which the currently running code is a part. The entity referred to by these keywords thus depends on the execution context. Different programming languages use these keywords in slightly different ways. In languages where a keyword like "this" is mandatory, the keyword is the only way to access data and methods stored in the current object. Where optional, they can disambiguate variables and functions with the same name.

<span class="mw-page-title-main">Python syntax and semantics</span> Set of rules defining correctly structured programs

The syntax of the Python programming language is the set of rules that defines how a Python program will be written and interpreted. The Python language has many similarities to Perl, C, and Java. However, there are some definite differences between the languages. It supports multiple programming paradigms, including structured, object-oriented programming, and functional programming, and boasts a dynamic type system and automatic memory management.

Haxe is a high-level cross-platform programming language and compiler that can produce applications and source code for many different computing platforms from one code-base. It is free and open-source software, released under the MIT License. The compiler, written in OCaml, is released under the GNU General Public License (GPL) version 2.

This article describes the syntax of the C# programming language. The features described are compatible with .NET Framework and Mono.

This article compares a large number of programming languages by tabulating their data types, their expression, statement, and declaration syntax, and some common operating-system interfaces.

A batch file is a script file in DOS, OS/2 and Microsoft Windows. It consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file. A batch file may contain any command the interpreter accepts interactively and use constructs that enable conditional branching and looping within the batch file, such as IF, FOR, and GOTO labels. The term "batch" is from batch processing, meaning "non-interactive execution", though a batch file might not process a batch of multiple data.

The syntax and semantics of PHP, a programming language, form a set of rules that define how a PHP program can be written and interpreted.

Swift is a high-level general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. and the open-source community. Swift compiles to machine code, as it is an LLVM-based compiler. Swift was first released in June 2014, and the Swift toolchain has shipped in Xcode since version 6, released in 2014.

References