Language Basics

The scripting language used in the iRoar applications is largely derived from the PAWN language. For detailed information on the scripting language, you can refer to the PAWN reference manual available online at https://www.compuphase.com/pawn/Pawn_Language_Guide.pdf.

In addition to the core modules, these libraries are also included in the iRoar SDK,

Variables

This section summarizes the common data types used as variables. All data elements are of type "cell" which can hold an integral number. The size of a cell is 4 bytes. To define a new variable,

new a = 10; //defines a variable with an initial value of 10
new array[4] = {0, 1, 2, 3}; //defines an array of 4 numbers starting from 0

You can define a tag, a custom data type, to enable type checking during compilation. For example to define a new error code,

const error_t{ //creates a new tag error_t
SUCCESS = 0,
ERROR_1,
ERROR_2,
};
//defines a variable err, which has a error_t type
new error_t: err;

Some of tags available are,

  • bool
  • Fixed, and
  • those defined in the Enumerations section.

The String data type is assumed to be an array with a size that is enough to hold all characters with a terminating '\0'. A String can be in packed or unpacked format,

  • A packed string uses 4 bytes per character. It's a series of zero or more ASCII characters surrounded by double single quotes.
    //This string has a size of 5 cells or 20 bytes.
    new ustring[5] = ''test'';
  • An unpacked string uses 1 byte per character. It's a series of zero or more ASCII characters surrounded by double quotes.
    //This string has a size of 2 cells or 8 bytes.
    new pstring{5} = "test";
    NOTE: When using strings in your application, do not allocate more cells than neccesary. The iRoar has limited memory, and keeping the memory usage small in your application enables the user to install more applications.

Functions

To increase modularity and portability of a program, large code segments can be refactored into multiple functions. There are two ways of passing variables into functions,

  • Arguments are passed by value. The function's arguments behave like local variables and any modification is local to the function.
update_value(val)
{
++val;
}
{
new a = 10;
update_value(a);
printf("New value %d\r\n", a); //This will print the number 10, and not 11
}
  • Arguments are passed by reference. The functions's arguments specified with this construct will have it's value returned to the caller.
    update_value(&val)
    {
    ++val;
    }
    {
    new a = 10;
    update_value(a);
    printf("New value %d\r\n", a); //This will print 11
    }