Global namespace

Following functions and variables that "live" in global namespace so they accessible in script without any namespace designator, e.g.

var r = eval( " 348.0 / 23.7 " );
stdout.printf( "%f" , r );

Global variables

These streams are created and managed by host application of the script engine

stdin
stream, standard input stream. Read-only.
stdout
stream, standard output stream. Write-only.
stderr
stream, standard error stream. Engine reports here about all uncaught exceptions.

Global functions

eval
( input : string|stream [, namespace :object | namespaces: array of objects ] ) : value

Evaluates (interprets) input and returns its value. If input is a string then function tries to interpret it as if it contains script source code. If input is a stream object then it compiles and executes source code from it.

Example: after execution of the following:

var obj = eval( "({ one:1, two:2 })" );

variable obj will contain object having two fields: one and two.

environment is an environment object - if provided then script execution takes place in the namespace of that object.

var env = { one:1, two:2 };
var res = eval( "one + two", env);
After execution of two lines above variable res will contain integer 3.

environments is a list of objects - environments - element with index 0 is inmost environment. 

These functions available only if host application configured the engine to use them.

parseData
( input : string|stream ) : value

a.k.a. JSON++ data parser.

Evaluates (interprets) data literal at the input and returns its value. Input shall contain valid data literal expression otherwise parsing exception will be thrown.

Example 1: after execution of the following:

var obj = parseData( " { one:1, two:2 } " );

variable obj will contain object having two fields: one and two.

Example 2: after execution of the following:
var v = parseData( "3.1415926" );

variable v will contain float number 3.1415926 - parsed value of the string.

Main difference from the eval function is that parseData will not parse and execute any function declarations or functions so it is safe to use this function when data is coming from unknown sources e.g. in AJAX like of interactions.

emit
( input :string|stream,output :stream[, env :object ] ) :value

Evaluates the input stream in serverScript mode (see below) and emits result to the output stream. Function assumes that executable script at the input is contained in <% %> brackets. Function returns result of first standalone return statement in the input stream.

env is an environment object, it allows to pass parameters to the input script from the caller.

load
( source [, asServerScript] ) :true|false

Loads (compiles and executes) source. Source here either string - file name or stream object. If asServerScript provided and equals to true then source is interpreted as a text with embedded script like PHP or ASP web page:

<html> ... <% =some_script_function(); %>... </html>

These two fragments:

load( "c:/myscripts/test.tis" );

and

var s = Stream.openFile("c:/myscripts/test.tis","r"); load( s );

are equivalent.

Script execution takes place in the namespace of the caller of the function.

loadbc
( source ) : true | false

Loads compiled bytecodes defined by source. Source here either string - file name or stream object.

compile
( input : filename | Stream, output: filename | Stream [, asServerScript: true | false ] ) : true | false

Calls built-in compiler to compile input. Writes output bytecodes into out stream or file. Bytecodes can be loaded (executed) later by loadbc function.

store
( filename | stream, value ) :true | false

Stores the value into file filename or stream in binary form. Returns true if data was stored successfully.

fetch
( filename | stream ) :value | null

Restores value previously written into the file (filename) or stream by function store. Returns value or null if operation failed.

$url
( ...relative path...)

Stringizier function, returns absolute URL composed from URL of this script file and the

Example:

// this file.tis is at "this://app/widgets/dialog.tis"
var componentsCss = $url(../styles/components.css);
assert componentsCss == "this://app/styles/components.css";
hash
( value

Returns hash value of its argument.

membersOf

( obj: object | function ) : map (object) is to be used in for( var (k,v) in membersOf(obj))

function Foo() { ... }
Foo.bar = 1; // adding property 'bar' to the
             // Foo function (that is an object too)
for(var (k,v) in Foo )
  ... // here you should see k equal to #bar 
// on some iteration

Returns map (simple object) that has the same set of properties as the obj. Main purpose of membersOf is to be used in for( var (k,v) in membersOf(obj)) alike enumerations to scan properties of entities that have different semantic of enumeration than in instances of Object. Example:

function Foo() { ... }
Foo.bar = 1; // adding property 'bar' to the
             // Foo function (that is an object too)
for(var (k,v) in Foo )
  ... // here you should see k equal to #bar 
// on some iteration
rand

( maxNumber : integer

Returns a random number between 0 and maxNumber-1. number of bytes from the system.

gc
( [factor:integer] ) : total:integer, free:integer , used: integer

Invokes garbage collector and returns: total VM heap memory size,  size of free area in the heap and size of used area by the script. total = free + used;

If factor is provided then the engine will try to reclaim allocated heap using the following rules:

Recommended value is 1. 

Note that VM requests twice as total number of bytes from the system.

crackUrl
( url:string )

Parses the url string. Returns an object having following fields:

symbol
: int,
( string ) : symbol

Function returns symbol of the string. Internally symbol is 32bit value so symbol space is limited - it makes no sense to "symbolize" arbitrary strings. function constructs color value from red, green, blue and opacity components or by parsing colorStr that can be #RRGGBB or name of the CSS color.

bopacity
color
(r: int, gbopacity

The color function constructs color value from red, green, blue and opacity components or by parsing colorStr that can be #RRGGBB or name of the CSS color.

em
( v: int | float ) : length, these functions constructs length values of correspondent type.
pr
( v: int | float ) : length
px
( v: int | float ) : length
cm
( v: int | float ) : length
pt
( v: int | float ) : length
dip
( v: int | float ) : length
flex
( v: int | float ) : length, flex unit value
rad
( v: float ) : angle, constructs angle value from float number of radians
deg
( v: int | float ) : angle, constructs angle value from number of degrees

JSON namespace

JSON.stringify
(value[, replacer: function | array][, space:string | integer]) : string

Produces canonical JSON string representation.

If the replacer is a function (key, value)  then it gets called for each key / value pair. The function shall return JSON compatible value. If replacer  is an array , only members with key values in the array will be converted. The order in which the members are converted is the same as the order of the keys in the array. The replacer array is ignored when the value argument is also an array.

If space is a string then all \t characters in output are replaced by that string. If it is a number then all \t characters get replaced by that number of spaces.

JSON.parse
(text:string[, reviver]) : value

Parses JSON string.  The reviver is a function (key, value): value or function (key, value): (key,value) - allows to transform parsed into another value or key/value pair.

URL namespace

Contains functions designated to work with URLs:

URL.parse
(url:string) : object

The function parses url and returns object containing URL components:

URL.relative
(url: string, baseUrl:string) : string

Makes url relative to baseUrl. So for: 

the function returns ../zar/laf.htm#location

URL.absolute
( relUrl: string, baseUrl: string ) : string

The function combines relative URL with base (absolute) URL.

URL.encode
( str: string ) : string

The function encodes all non-url characters, space for example will be replaced by %20 , etc.

URL.encodeParam
( str: string ) : string

The function encodes all characters except the following: alphabetic, decimal digits, - _ . ! ~ * ' ( )

URL.decode
( str: string ) : string

The function decodes URL encoded string to its original form.

URL.toPath
( fileUrl: string ) : string

The function converts "file://..." string to a path to file - path string suitable for target platform. 

URL.fromPath
( path: string ) : string

The function converts path (like C:\User\Desktop) to file URL (like file://C:/User/Desktop).