Script Reference : Syntax

Formal syntax specification can be found on the squierell web site. On this page some basic things are shown.

Comments

A comment is text that the compiler ignores but that is useful for programmers. Syntax is same as in in C or C++.

/* Comments can contain keywords such as
   for and while without generating errors. */

or

print("hello");// This is a single line comment

Variables and Types

Basic types are integer, float, string, null, table, array, function, generator, class, instance, bool, thread and userdata.

Integer:
local a = 100 //decimal
local b = 0x64 //hexadecimal
Float

A float represents a 64 bits floating point number.

local a=1.0
local b=0.234
String

Strings are an immutable sequence of characters to modify a string is necessary to create a new one.
Strings can contain escape sequences(\t, \a, \b, \n, \r, \v, \f, \\, \", \', \0, \xhhhh).

String functions
Name Return Type Description
len() int Returns length of the string
tointeger() int Converts the string to integer and returns integer value.
tofloat() float Converts the string to float and returns float value.
slice(start,[end]) string Returns a section of the string as new string. Copies from start to the end (not included). If start is negative the index is calculated as length + start, if end is negative the index is calculated as length + start. If end is omitted end is equal to the string length.
find(substr,[startidx]) int Search a sub string(substr) starting from the index startidx and returns the index of its first occurrence. If startidx is omitted the search operation starts from the beginning of the string. The function returns null if substr is not found.
rfind(substr) int Search a sub string(substr) from the right
tolower() string Returns a lowercase copy of the string.
toupper() string Returns a uppercase copy of the string.

 

local str="Text"

Null

The null value is a primitive value that represents the null, empty, or non-existent reference.

local a = null;
Bool

The boolean data can be only true of false.

local a = true;
local a = true;
Table

Tables are associative containers implemented as pairs of key/value (called a slot). In priPrinter can be used for passing configuration paramers to several functions. For instance SaveAsPDF.

Array

Arrays are simple sequence of objects, their size is dynamic and their index starts always from 0.

local a=["I'm","an","array"];
local b=[null]; // array with one null item
local b=[];// empty array
b[0]=a[2];
b.append(c);// appends the value ‘c’ at the end of the array
b.len();// length of array

 

Functions

Functions are very simialr to functions in other languages.

function FitPage(paper,page)
{
	local dst=paper.GetAreaSize();
	local src=page.GetAreaSize();
	local scaleW=dst.x/src.x;
	local scaleH=dst.y/src.y;
	if(scaleW>scaleH)
		scaleW=scaleH;
	local delta=dst-src*scaleW;
         delta/=2.0;
	paper.SetPageScale(page,scaleW);
	paper.SetPagePos(page,delta);	       
}

or

function test(a)
{
 return "["+ a +"]";
}
print(test("----"));

 

if/else

if(scaleW>scaleH)
    scaleW=scaleH;
else scaleH=scaleW; 

for

 local i;
for(i=0;i<count;i+=1)
 {
  	local page=doc.GetPage(i);
	page.visibility=true;
	page.selected=true;
 }

while

local a=0;
do
{
print(a+"\n");
a+=1;
} while(a<10)

 

This specification is partially based on Squirell programming language reference.