Content


KoalaScript Object Reference


KoalaScript supports some built-in objects. Each object has its own methods and properties. You can call object methods to carry out tasks, get object properties to get information about the object, or set object properties to change status of the object.

Right now KoalaScript provides the following built-in objects:

Terminal object

Terminal Settings

System Object

File Object

String Type

KoalaScript Sample

Terminal Object

When a script is started, KoalaScript creates a global variable "term". The value of the variable is a terminal object. This object represents the functionality of a KoalaTerm session. It supports the following methods:

1. Wait ( <wait string>, <timeout>,<callback> )

2.   Send ( <sequence> )

3.  Get ( <number of characters>, <timeout> )

4.  Screen (<starting row>, <starting column>, <ending row>, <ending column>) (Available since version 3.14)

5.   DoMenu ( <menu item name> )

6.   MapKey ( <PC key code>, <modifiers>, <VT key code>, <string> )

7.   Clear ()

This function clears the terminal screen, and resets terminal status as well.

8.   SendLocal ( <sequence> )

This function sends the sequence to the terminal itself, without going out to the host. This allows you to control the terminal like from a host. The syntax of "sequence" string is the same as used in key mapping and "Send" function.

9.   SendBreak ()

This function sends a break signal (only effective for serial connections).

10.   Capture ( <File Name> ) (Available since version 3.3 build 1625)

This function start or stop capturing terminal content (from the host) into a file. When you start capturing, the <File Name> parameter is required for the path and name of the captured file. When you stop the capturing, do not specify file name.

11.   Disconnect () (Available since version 3.3 build 1701)

This function disconnect the session immediately.

Terminal Settings

Terminal object also has many properties you can get and set. The properties are actually corresponding to available KoalaTerm settings. You can also get terminal status like current cursor position using some of the properties. Here is a complete list of supported properties:

A complete listing of terminal settings


System Object

When a script is started, KoalaScript creates a global variable "sys". The value of the variable is a system object. This object provides functionality of Windows system. It supports the following methods right now:

1. MessageBox ( <message>, <title>, <style>)

2. PlaySound ( <file name> )

3. Sleep ( <number of milliseconds> )

4. OpenFile ( <file name>, <open mode> )

5. System ( <command> )

6. LoadSession ( <file name> )

7. InputBox ( <prompt>, <default value>, <style> ) (Available since version 3.12)


File Object

A file object needs be created by sys.OpenFile method first. Right now file object supports the following methods:

1. Write ( <string> )

2. Close ()

3. ReadLine () (Available since version 3.12)

4. Read ( <number of bytes> ) (Available since version 3.12)


String Type

KoalaScript supports several operations on strings:

1. Length

2. Mid ( <start position>, <byte count> ) (Available since version 3.15)

3. MakeUpper () (Available since version 3.15)

4. MakeLower () (Available since version 3.15)

5. Find ( <substring>, <start position> ) (Available since version 3.15)


KoalaScript Sample

The following example shows a file logging procedure.

The host first sends file header record starting with a tag, then unlimited number of records in file, at last it transmits a file trailer record starting with another tag, following the trailer tag there are fixed number (40) of characters in the trailer record.

// First, we need a wait callback function to do the file logging

// during waiting for the trailer record tag
function OnRecv( char )
{
    // write every character in file
    file.Write( char );
}
// Start of script
// Wait for the file header tag first
str = term.Wait ( "[HEADER ]", 30 );
// Check if we actually get the header tag in 30 seconds or not
if ( str == "" ) {
    sys.MessageBox ( "Cannot detect the file header." );
    return;
}
// Open the file for writing
file = sys.OpenFile ( "MyLog.txt", "w" );
// Write the header tag into file since it’s also a part of the file
file.Write ( str );
// Wait for the file trailer tag, and log every character into file
term.Wait ( "[TRAILER]", 0, OnRecv );
// Finally, get fixed number of characters in the trailer record
str = term.Get(40);
// And write to the file
file.Write ( str );
// We are done. Close the file
file.Close ( );

How to Invoke KoalaScript Scripts

Overview of KoalaScript Language


Content