Home Notices Documents Classes Download Others Rice
Documents  >  tutorial  >  Basic usage  >  Requirements
Requirements for Rice source code

Purpose of this page

CookerGX is an application that loads and executes scripts written in the Rice language. Therfore, it firstly needs a properly written Rice script for CookerGX.

In this page, we will learn what is needed for the CookerGX's Rice script using samples.

File requirements

Before illustrating the sample, we will discuss the requirements that the files in the sample should meet.

The following is the requirement.


The Rice script file for CookerGX is a UTF-8 encoded text file and must have the .cgx extension.


This is really important, if not encoded in UTF-8, the message from CookerGX may be garbled.

In addition, this UTF-8 encoding issue also applies to text files other than Rice script files.

For example, the sample archive contains a .js files. This is a text file containing JavaScript source code, but this also need to be encoded in UTF-8.

That's because this .js file is loaded into the Rice script and becomes part of the Rice script.

If the encoding of this file is different, there is a high possibility of encountering unexpected garbled characters.


Based on the above, we will revise the requirements.


The Rice script file for CookerGX is a UTF-8 encoded text file and must have the .cgx extension.

Text files handled by Rice script must also be encoded in UTF-8.


Minimal Rice script

"Sample_001.cgx" in the sample archive is shown below. This is a minimal Rice script written for CookerGX.

1:

class main

2:

open method void start()

3:

endmethod

4:

endclass

The script execution method will be described later, but this script can be executed on CookerGX without any problems. However, there is no meaning to execute.

Nothing happens when it is executed because this script does not have any meaningful action.

This script is a minimal and meaningless, but it contains several important points as a CookerGX Rice script.

In the section below, let's look at the important points included in this script.

Class definition and main class

See the example script above. It starts with the word class followed by the word main and ends with the word endclass.

A series of words starting with class and ending with endclass is called a class definition in Rice. This class and endclass are special words that indicate the beginning and end of the class definition, and such special words are called "keywords" in Rice.

Class definition is the most important element in Rice. That's because the largest element that makes up the Rice script is the class definition.

In the class definition, the word following the class keyword is the specification of the class name. In the above example, the word main follows the class keyword. Threfore, this definition is the definition of the main class.

The main class is a special class. In the Rice script, the definition of the main class is absolutely required.





The above example is the definition of the main class only, but you can define any number of classes if the class name is valid.

start() method

Look at the second and third lines of the example script above. Here is the content of the class definition.

The start() method has been defined here, that is, an argumentless method with the name start.

The rules for method definition will be explained in more detail later. Please remember like the figure below. That's enough for now.





The important thing here is that the start() method of the main class is a special method.


When CookerGX is instructed to execute Rice script, it firstly tries to execute the start() method of the main class. the method will execute if it is in the script , otherwise it will give an error and abort the execution.

In CookerGX, the start() method of this main class is the entry point of script execution. All scripts must have this form.

Comment

The above script example is a good starting point for Rice scripts, but there are some elements that should be explained before you build the script.


The first is "comment". Comments are annotations that unrelated in program execution.

Rice has two types of comments, but please remember single-line comments here. The rule of single line comment is as shown below.





The point is that anything between the double slash (//) and the end of the line will be ignored at runtime.

end() method

The second is the end() method. The end() method is shown below.

1:

open method void end()

2:

endmethod

The end() method is a pair of start() methods. The start() method is called when the script starts, the end() method is called when the script ends.

However, the definition of the start() method is required, but the definition of the end() method is optional.

CookerGX tries to execute the end() method of the main class at the end of the execution of Rice script. If this is in a script, execute it, otherwise do nothing.

Template of Rice scripts

sample_002.cgx is shown below. The above elements have been added to sample_001.cgx. This is the template for Rice scripts that use in this tutorials.

1:

// Definition of the main class.

2:

class main

3:

// Definition of the start () method. Required.

4:

open method void start()

5:

// Implement here.

6:

endmethod

7:
8:

// Definition of the end () method. Not required.

9:

open method void end()

10:

// Implement here if necessary.

11:

endmethod

12:

endclass

How to execute script

Describes how to execute a script.


When CookerGX has been executed, you can execute the script by selecting the .cgx file from the file selection dialog.


There are two ways to open the file selection dialog.

The first way is a key input. Press Ctrl + R key to open file selection dialog.

The second way is a mouse click. The file selection dialog will open if right-click anywhere on the browser.


Next
Previous
Copyright © CookerGX All rights reserved.