Shiny Language Reference
Language Reference > Basic Types
Basic Language Types
string
int
double
dword
bool
The basic variable types
Shiny uses 5 basic types to represent variables and constants. These basic types support implicit type conversion, allowing a variable of one type to be assigned to another type with no explicit conversion required. A comprehensive tutorial on these types begins here.
The Shiny compiler acts in the same way as the Visual Basic "Option Explicit" statement, in other words all variables must be declared before they are used. Variables may be declared in one of two ways:
- Using the Visual Basic-like DECLARE statement.
- Using the C-like declaration syntax
An example VB-like declaration. This statement declares a variable called "MyNumber" as an integer.
declare MyNumber int;
The same declaration using C-like syntax:
int MyNumber;
The compiler produces identical code for both of these statements. In their default form as shown there is no benefit in using one instead of the other, simply pick the style you are comfortable with.
The C-like syntax has one extended benefit over the VB-like syntax. As with C, it is possible to perform a declaration and assignment in a single step:
int MyNumber = 99;
The VB-like syntax equivalent of this is as follows:
declare MyNumber int;
MyNumber = 99;
The compiler generates identical code for both syntax styles. The difference is simply visual.
Arrays
To create an array, alter the variable declaration as follows. VB-like:
declare MyNumberArray [10] int;
C-like:
int MyNumberArray [10];
To assign a value to an array element, simply specify the variable name followed by an opening square bracket, followed by the element to assign, followed by a closing bracket. This sample assigns the value 20 to the fourth array element (array access is zero based) of MyNumberArray.
MyNumberArray[3] = 20;
You may declare an array of zero size, then use realloc to resize it. It is not possible to perform a 1-step declaration and assignment using C-like syntax when an array is required. This is invalid code:
int MyNumberArray[10] = 99;
Global Variables
By default, all variable declarations are assumed to be local scope. To declare a variable with global scope use the following syntax. VB-like:
// Global string variable
declare global MyString string;
// Global string array variable
declare global MyString [10] string;C-like:
// Global string variable
string global MyString;// Global string array variable
string global MyString [10];
The Shiny compiler does not implement scope in the manner of a traditional language like C or VB. This is done for ease of use, as variable naming conflicts are completely prevented. Scope is discussed in detail in this tutorial.
Type descriptions
Variable Type Contains string Any text string: "My name is Bob", "Brass is great" etc. int A whole number: 1, 99, 2500 bool A boolean value, either True or False double A whole number or floating point number: 5, 27, 3.1415 dword A base 16, 4 byte value: 0xffffffff, 0x12345678 For ease of use some types support dual syntax. The only difference in using alternative syntax is the appearance of the source code, the compiler produces exactly the same code regardless of what synonyms are used. It is legal to mix synonyms, for example by using INT on line 1 then NUMBER on line 2.
Variable Type Synonym int number double float dword long
Type conversions
All types listed here support implicit type conversion. Type conversion is discussed in this tutorial. The following tables show the result of assigning dissimilar types to each other:
integer to string Converts integer to a string representation string MyString = 99; MyString equals "99"
boolean to string Converts boolean to a string containing "True" or "False" string MyString = True; MyString equals "True"
double to string Converts double to a string representation string MyString = 3.1415; MyString equals "3.1415"
dword to string Converts dword to a string representation string MyString = 0xABCD1234; MyString equals "0xABCD1234"
string to integer Converts string representation of a number to an integer int MyInt = "99"; MyInt equals 99
boolean to integer Converts boolean True to integer 1, False to integer 0 int MyInt = True; MyInt equals 1
double to integer Floors the fractional component of a double int MyInt = 3.1415; MyInt equals 3
dword to integer Converts dword to a signed integer int MyInt = 0xABCD1234; MyInt equals 2882343476
string to bool If the string is "true", "True", or "TRUE" the bool is set to True, otherwise the bool is set to False. bool MyBool = "True"; MyBool equals True
integer to bool If the integer is greater than zero the bool is set to True, otherwise the bool is set to False. bool MyBool = 99; MyBool equals True
double to bool If the double is greater than zero the bool is set to True, otherwise the bool is set to False. bool MyBool = 3.1415; MyBool equals True
dword to bool If the dword is equal to 0x00000000 the bool is set to False, otherwise the bool is set to True. bool MyBool = 0xABCD1234; MyBool equals True
string to dword Converts string representation of a dword to a dword dword MyDword = "0xABCD1234"; MyDword equals 0xABCD1234
integer to dword Converts integer to a dword (base16/hexadecimal) dword MyDword = 99; MyDword equals 0x00000063
bool to dword If the bool is True, the dword is set to 0xffffffff, otherwise the dword is set to 0x00000000 dword MyDword = False; MyDword equals 0x00000000
double to dword Floors the double and converts it to a dword (base 16/hex) dword MyDword = 3.1415; MyDword equals 0x00000003