Home News DOC Class DL Others Rice
DOC  >  Tutorial - Basics  >  Requirements for Rice source code
Requirements for Rice source code

Purpose of this page

As mentioned earlier, Cooker is a software classified into the category such as Web automation and Web scraping.

It loads and executes a script written in the Rice language in order to directly operate a web page. Moreover, scripts do more than just page manipulation. Cooker's own settings are also manipulated via the script.

Cooker does not have a user interface for the settings. Instead, it has exposed its settings in the form of Rice class attributes.

In Cooker, everything is done with a Rice script. So, first of all, you need a correctly written Rice scripts.


Table of contents:


Requirements for files

Minimal Rice script

Class definition and main class

start() method

Comment

end() method

Template for Rice scripts

How to execute script

Requirements for files

The following is the requirement which the Rice source file must meet.


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


Please be especially careful in regions that use multi-byte characters. If it is not encoded in UTF-8, the message from the script may be garbled.


It is recommended that the text files related to Cooker encode in the UTF-8.

Mixing encodings between text files which are loaded to Rice scripts may lead to unexpected garbled characters.

You can handle different encodings at same time if you are careful, but if you unify the encodings, you don't have to do like this.

Since the encoding of Rice script files is fixed to UTF-8, it is recommended to encode other text files in UTF-8 as well.


Minimal Rice script

First, it will show you the minimum Rice script.

1:

class main

2:

open method void start()

3:

endmethod

4:

endclass

This script can be executed on Cooker 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 Cooker 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 "class" followed by the "main" and ends with the "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" is the specification of the class name. In the above example, the "main" follows the "class". Threfore, this is the definition of the "main" class.

The main class is a special class in the Rice script. Because, 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 and different.

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".

See Methods for more information about method definition rules. Please memorize 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 Cooker is instructed to execute Rice script, it firstly tries to execute the start() method of the main class. the method will execute if it exists in the script, otherwise it will give an error and abort the execution.

In Cooker, 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.

Cooker tries to execute the end() method of the main class at the end of the execution of Rice script. If it exists, execute it, otherwise do nothing.

Template for Rice scripts

The following is a minimum Rice script with the above items added. This will be the template for the tutorials that follow.

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

There are four way that run the Rice script on the Cooker.

The first way is to drop a .cook file to Cooker's icon.

The second way is to drop a .cook file to the script tile.

The third way is to select a .cook file from the file selection dialog.

The fourth way is a shortcut key.


The second method is briefly explained below.

After launching Cooker, drop the .cook file on the script tile.

Script tile is colored area on the right side of the window. Drag and drop the .cook file from Explorer here to run the script.

Script tile

Note: Drag and drop the .cook file into the browser area will not run the script. The contents of the file will be shown .

Copyright © Cooker All rights reserved.