Home News DOC Class DL Others Rice
DOC  >  Usage  >  JavaScript extension
JavaScript extension

JavaScript extensions.

Cooker's Javascript provides some objects as extensions under the window object.

window.cooker.external object

1:GetData(token)Receives a string set in Rice. It is an asynchronous function.
2:SetData(token,object)Pass a string to Rice. It is an asynchronous function.
3:Notice(token,object)Fires the Notice event of the Rice:jsexecutor class. It is an asynchronous function.

First argument, token, is a string that represents 32-digit number. It is given at the time of the conversion.

An example of using GetData(token). Receives a string set by Rice:jsexecutor.

1:

let stringDataFromRice = await window.cooker.external.GetData(token);

An example of using SetData(token,object). Sends a string to the Rice:jsexecutor.

1:

window.cooker.external.SetData(token,"string data to Rice.");

An example of using Notice(token,object). Fires the Notice event of the Rice:jsexecutor.

1:

window.cooker.external.Notice(token,'A string data which will be passed to the Rice.');

window.cooker.data object

The string set in Rice:jsexecutor is also set in this object.

1:

let stringDataFromRice = window.cooker.data;

window.cooker.storage object

1:Write(token, filename, data, append)Write the text data to a file. It is asynchronous function.
2:Read(token, filename)Read text data from a file. It is asynchronous function.

File writing example:

1:

window.cooker.storage.Write(token, "example.txt", "data string", true);

Arguments

FirsttokenA string that represents 32-digit number. It is set at the time of the conversion.
SecondfilenameA file name.
ThirddataA string for data.
FourthappendA boolean value. Append is true. Overwrite is false.

Give only a file name as the third argument. File I/O is restricted to direct child files in the storage subdirectory within Cooker's execution directory.

If a path is given, only the file name is extracted from the path and treated as a direct child file of the storage subdirectory.


File reading example:

1:

let data = await window.cooker.storage.Read(token, "example.txt");

Arguments

FirsttokenA string that represents 32-digit number. It is set at the time of the conversion.
SecondfilenameA file name.

Note to the file name. It is restricted similar to Write().

Note that the entire data in the file is retrieved.

Next
Previous
Copyright © Rice All rights reserved.