- Smart Personal Cloud

Star Script Tutorial

1

Star Script is the language behind applications within the MyEZApp.com system. This simple programming language is designed to enable non-programmers to build powerful applications through intuitive, natural commands.

Star Script works by taking arbitrary input (i.e, "hello world") and extracting programming structure during compilation. Based on that programming structure, the script is executed and results are displayed. To make it easier to analyze a program written in Star Script, the editor displays the program in a tree structure

2

If you want to try out Star Script, just open a Star Script Editor. This editor is a playground for you to try out the language. It does not allow you to save files or access database. If you want to develop applications on myezapp.com, you should register for a myezapp.com account and use the File Manager. The myezapp.com File Manager is the IDE (integrated development environment) for the Star Script language.

To use the File Manager: - Click on the Files Icon from the System Tab on the main home screen. This will open the File Manager. - There are two ways to program in Star Script. - One way is to click on a .ws file from the file tree on the left-hand side of the File Manager. This will open the script in the Star Script Editor. - The other way is to click the "new button" and create a blank .ws file. This will allow you to start scripting from scratch.

Alternatively, you can download and install the Star Script compiler to run it in your local environment.

3

Star Script recognizes values such as number and text. Text needs to be enclosed in the double quote ("). If you want to use Star Script to calculate an expression. You can directly enter it. For example, if you enter

1+1

you will get

2

If you want to display the text 1 + 1 instead of getting it evaluated. You need to enclose it inside the quote, such as

"1+1"

you will get

1+1
4

Comments represent those elements within a script that are not part of the intended output but, instead, are meant to clarify other expressions, operations, or activities within the script. Star Script supports C-style comments. You can use // to skip a single line or /* */ to skip groups of lines.

// this is a single line comment /* hi, you can ask Star Script compiler to ignore multiple lines of comments */
5

Variables allow you to assign value to a placeholder. For example, in the following statement,

var name = "hello"

The variable "name" is assigned a value of the string "hello". Later on in your script where you make use of the variable "name", such as in the example below, the output will replace "name" with "hello".

welcome name

The output of the script is

welcome hello

Variable names are not globally visible. They belong to scopes. For detailed explanation of scope and its rules, please refer to the next section.

Star Script supports several common primitive types. These include: - String (/lang/string.string) - Integer (int) - Floating Point Number (float) - Boolean (bool) - Character (char), and - Byte (byte)

Specifying a type of variable is optional. Based upon its use, Star Script will attempt to infer the kind of variable. So, for example

var name as string = "hello"

produces the same result as used in example before.

6

A variable has a value. The value of a variable can be changed using the assignment statement.

The assignment statement syntax is

<variable name> = <value expression>

Value expression can be in many forms, such as literal, expression, or function call. For example,

var number as int    // this declares the variable number    number = 1 + 1       // this is the assignment statement, that assigns the result of 1+1 to the variable "number"
7

All Star Script names (variable names, function names and class/interface names) belong to a scope. Star Script has the below scopes: - Script Scope - Block Scope - Function Scope - Class Scope

Script Scope

Script scope defines the names that can be referenced within the script. Variable names defined outside any programming blocks are in the script scope. Any variable defined inside a tag, if statement, loop structure, function body, class, are not in the script scope.

Variables defined in the script scope are visible anywhere after the variable declaration, except the class declaration.

Block Scope

Block scope is the scope defined for a block of program. Below are the list of programming structures that are treated as blocks: - Tag - If statement - For loop - DoWhile loop

Variables defined in a block can only be referenced inside that block. They are not visible outside the block.

Function Scope

Function scope refers to the scope of a function body. Variables defined in a function body cannot be referred to outside of the function body.

Class Scope

Class scope refers to the scope of a class body. Variables defined in a class body can only be referred through the object reference syntax. For example, you can define a class person with a variable firstname. When you create an instance of the class person, for example

var per = new person()

You can refer to the firstname of that person using

per.firstname

Without the object reference "per", you cannot directly refer to firstname outside of the class definition.

8

Loops are powerful logical constructs within programming. These enable you to create repeated actions that continue to happen so long as a given condition is met.

Star Script supports two types of loops: - For-loop, and - DoWhile loop

For Loop

Below is an example of for-loop,

for i = 1 to 3 we are at line i \n next

you will get

we are at line 1 we are at line 2 we are at line 3

Each for-loop takes a loop variable. In the above example, the loop variable is "i". You can specify the starting number and ending number for the loop variable. At each step, the loop variable "i" will increase by one. Each for-loop ends with the keyword Next. If you want to increase the counter more than one at a time, you can optionally use the Step keyword.

for i = 1 to 20 step 6 i \n next

you will get

1 7 13 19

A common structure in a web page is a table. Below is an example of how to generate a table,

<table>   for i = 1 to 3     <tr>        <td style="border:1px solid black;">i "*" 2 =</td>         <td style="border:1px solid black;">i*2</td>      </tr>   next  </table>

you will get

1 * 2 = 2
2 * 2 = 4
3 * 2 = 6
DoWhile Loop

Another loop structure is DoWhile loop. Below is an example of a DoWhile loop:

var i = 1 DoWhile i <= 3 we are at line i \n i = i + 1 End

you will get

we are at line 1 we are at line 2 we are at line 3

The above DoWhile-loop is equivalent to the for-loop example referenced previously.

9

Condition statements (using "if" and "elseif") are powerful logic gates within any program. Star Script supports conditional statements enabling you to make more complicated programs.

if 2 > 1 then hey, "2 > 1" end

you will get

hey, 2 > 1

If you have multiple branches, you can use the Elseif keyword. For example:

if 1 > 2 then Oops! "1 > 2" ??? elseif 2 > 1 then right "2 > 1" end

you will get

right 2 > 1
10

A function defines a re-usable block of code. It�s basically a container for activites within a program that you wish to call repeatedly. A function takes one or more parameters (variables that you send to the function when you wish to execute the code in it) and returns results. Functions can save a lot of time when programming as they allow you to utilize a block of code anywhere in your application without having to retype the block of code each time you want to use it. The following is an example function that calculate the sum from 1 to n.

func sum(n as int) as int   var s = 0   for i = 1 to n     s = s + i   next   return s end

In Star Script, you can use eiher a reference to call a function or a tag to call a function. Below is an example of using reference format,

sum(10)

The above example will output:

55

You can also call the function in tag format, for example:

<sum n=10/>

will produce the same result as calling the function using "sum(10)". In Star Script, every function definition is a tag definition at the same time.

Functions are very powerful for creating more organized, reusable code.

11

Star Script is an object oriented programming language and therefore, supports classes. A class defines the blueprint of a type of objects. Below is an example of class person.

class person   var _firstname as string   var _lastname as string      func person(firstname as string, lastname as string) as string     _firstname = firstname     _lastname = lastname   end      func getFullName() as string     return _lastname + ", " + _firstname   end end var p = new person("John", "Doe") p.getFullName()

Running the code will produce the following output

Doe, John
12

Star Script recognizes tags similar to HTML and XML. This allows you to combine powerful scripting functionality with an extensible structure. A tag might be,

<sayhello/>

Star Script will attempt to match the tag to a class or function. If none are found, the tag will be printed to screen. If there is a match, the program will carry out the required activities. So using the example above, if there were a corresponding class, it might be written as such:

class sayhello extends component   func process()     Hello World!   end end

In order for a tag to have a relationship with a class, the class must "extend component" as well as include the "func process()" for rendering. Tags, though, can also reflect functions. For example,

func sayhello(name as string)   Hello name! end

When using this, the tag must include the variable that the function requires. So, to invoke this function within a tag, you would type:

<sayhello name = 'my dear user'/>
13

Star Script has a built-in database you can use to store application data. To access the database, you need to use the Star Script database statements: Save, Load, Select, and Delete. Below is an example,

class person   var _firstname as string   var _lastname as string      func person(firstname as string, lastname as string) as string     _firstname = firstname     _lastname = lastname   end      func getFullName() as string     return _lastname + ", " + _firstname   end end var p1 = new person("John", "Doe") var p2 = new person("Richard", "Roe") save p1 save p2 var p = load person withid p1.oid() var persons = select person for i = 1 to persons.length   persons[i].getFullName()   delete person withid persons[i].oid() next

Running the code will produce the following output

Doe, JohnRoe, Richard

For more information on the build-in database function, please refer to this Tutorial.

14