Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.5b

Application v 5.24b

  

 

Chapter ThreeData Types and Operators (continued)

3.3 Data Types

3.3.1 Overview

All variables within the program must have a data type. The following are the fundamental types:

Integers

Integers are used to represent whole numbers and can be of various sizes. The range of an integer is determined by two factors: the number of computer bits used to represent the number and whether the value is signed or unsigned. For example, an 8-bit, unsigned integer can represent numbers from 0-255 while the same when signed can represent -128 to +127.

The size modifier for an integer is often specified by terms such as “short” or “long”. The intent is that short and long provide different lengths of integers where practical. A “short int” is 16-bits long, and a “long int” is 32-bits. Legato does not use modifiers such as “short”, “long”, or “unsigned” as other languages do. Rather, a short simply means a 16-bit integer. When a value is to be treated as unsigned, the data type word or dword is used to indicate that the value is never negative and should be treated as a simple positive number. Unsigned values are very useful when dealing directly with ‘bits’ of numbers.

Integers have the characteristic of being exact whole values (as opposed to floating-point or real numbers discussed below). When performing math, the expression:

a = 10;

x = a / 3;

 

will yield x=3. The fractional amount .333333... is truncated.

Further, integers do not have an intrinsic base type. For example, an integer is not base 10 or base 2. When an integer is translated from computer representation, it is translated to the appropriate base (usually base 10).

When an integer is used to access an element of an array, it is always expected to be 0 or larger. All integer based numbers are stored as 64 bits unless placed into an array or object.

During runtime, ranges are checked and a warning issued if values cannot be stored in the declared type. Over sized values are truncated (bits are clipped off) or capped depending on the data type. The following are truncated:

char
byte
wchar
word
dword

The following types are capped:

boolean
short

Anytime a value is truncated or capped, a warning is added to the log. For example:

Warning 1191 line 12: Expression resulted in a truncated value.

Floating-Point

Floating-point describes a method of representing an approximation of a real number. The numbers are generally expressed as a fixed number of significant digits (the mantissa) that is scaled via an exponent (typically base 2 or base 10). Floating-point numbers have limited precision. Legato employs the IEEE 754 double precision format, which will give a maximum relative error due to rounding in the order of 1.11e-16. Larger errors can be generated by non-elementary arithmetic operations, and, errors can propagate when several operations are performed in sequence.

Conversion between base 10 (commonly used by people) and base 2 (used by computers) can lead to other issues, as rational numbers that are exactly representable as floating-point numbers in base 10, like 0.2 or 0.5, do not have an exact representation as floating-point numbers in base 2. Because of this, there is an inherit loss of precision in the conversion process. Direct comparison between floating-point numbers is therefore tricky and unadvisable, as comparing the binary representations may cause incorrect results.

Legato does not differentiate between float and the commonly used double data type. All floating-point numbers are treated as 64-bits.

Characters

Characters represent an 8-bit value for an ASCII, ANSI or ISO-8886 value (the value need not be an actual character). The valid range is 0-255.

In some languages, a char represents a signed 8-bit value. Since char represents characters, that convention is actually meaningless and interferes with checking high characters (128 and above) against ranges of low characters.

Strings

Strings refer to sequences, or arrays, of characters. Unlike C++, which often requires a firm definition of the size of a character array, Legato allows strings to be auto-allocatable. This means that a string can grow infinitely large within the memory constraints of the system. Strings and character arrays behave nearly identically, with the exception that a string is automatically set as auto-allocatable while a character array must be explicitly declared that way. For example:

string s;  // String s

char s[];  // Character array s - auto-allocatable

char s[6]; // Character array s - set to six characters 

Strings can be 8-bit or 16-bit. 8-bit strings typically represent ASCII, ANSI or ISO-8859 characters, 16-bit strings generally represent Unicode. In either case, string are generally terminated by a zero character (\0). Unless otherwise specified, zero termination is the norm.

Handles

A handle references an abstract item such as an object or a window. Handles are typically numeric; handles cannot be equal to 0. In Legato, handles (and the items that they reference) are either managed by the script engine or unmanaged.

Clusters

Objects and other abstract items are considered clusters. Cluster variables can, in and of themselves, contain other data types and other clusters. Clusters may be referenced by handles.

3.3.2 ‘int’ Integer (32-bit signed)

An int specifies a 32-bit signed numeric value ranging from -2,147,483,648 to 2,147,483,647. When setting an integer the negative is ranged as well as positive.

To remain compatible with passing 32-bit formatted error codes, positive values are allowed to 0xFFFFFFFF without a warning. A warning is not added to the run time log unless the positive value exceeds 4,294,967,295.

3.3.3 ‘short’ Integer (16-bit signed)

A short specifies a 16-bit signed numeric value ranging from -32,768 to 32,767.

3.3.4 ‘long’ Integer (64-bit signed)

A long specifies a 64-bit signed numeric value ranging from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

3.3.5 ‘float’ Float (64-bit)

A float specifies a 64-bit floating-point number. For Intel and AMD, this follows the IEEE 754 standard (see above as well). The value is made up of an 11-bit exponent representing a value from -1024 to 1023 and 53-bit mantissa, allowing for 15 to 17 decimal digits of precision. Note that floating point numbers are meant to represent real numbers allowing for a trade-off between range and precision. For certain accounting and other applications fixed point is a better solution. In addition, floating point, while providing a wide range of values, can suffer from normalization issues such as failure of equal comparison. See Wikipedia Floating-Point Arithmetic for additional information.

3.3.6 ‘boolean’ Boolean 

A boolean specifies a logical value, either TRUE or FALSE. TRUE is also equated to any non-zero value and FALSE equates to zero. Boolean values are stored as an 8-bit signed value with the range -128 to 127. This allows for programmers to set indeterminate or unknown values as -1. However, since an expression is treated as true if the value is non-zero, affirmative tests for TRUE and FALSE should be performed. For example:

if (flag == TRUE) { ...

Not ...

if (flag) { ...

Or ...

if (flag != FALSE) { ...

If indeterminate values are not used, these precautions are not necessary.

3.3.7 ‘char’ Character (8-bit)

A char specifies an 8-bit character. Values are equatable to integers from 0-255.

3.3.8 ‘byte’ Byte (8-bit)

The byte and char types are synonymous. A separate designation is provided for clarity purposes since byte is frequently used by Windows programs to present arrays of 8-bit values or buffers. Values are equatable to integers from 0-255.

3.3.9 ‘wchar’ Wide Character (16-bit)

A wchar specifies a 16-bit character, typically used for Unicode characters.

3.3.10 ‘string’ String (8-bit characters)

A string specifies an array of 8-bit characters. Strings are auto-allocatable. Individual characters can be referenced by an integer character position (zero-inclusive) within the string. Depending on the context, some functions expect strings to be Unicode Text Formatted (UTF). This is particularly true of filenames and paths. This allows for a wide range of character representations within the scope of an 8-bit string.

3.3.11 ‘wstring’ Wide Character String Array (16-bit characters)

A wstring specifies an array of 16-bit characters. Strings are auto-allocatable. Individual characters can be referenced by an integer character position (zero-inclusive) within the string.

3.3.12 ‘word’ Unsigned (16-bit)

A word specifies a 16-bit unsigned numeric value ranging from 0 to 65,535.

3.3.13 ‘dword’ Unsigned (32-bit)

A dword specifies a 32-bit unsigned numeric value ranging from 0 to 4,294,967,295.

3.3.14 ‘qword’ Unsigned (64-bit)

A qword specifies a 64-bit unsigned numeric value ranging from 0 to 18,446,744,073,709,551,615.

3.3.15 ‘handle’ General Handle (32-bit)

A handle specifies 32-bit numeric value that represents an abstract object in memory or in some other location. 

3.3.16 ‘void’ Empty Declaration

A void definition allows a function to be declared without a return value.